Satisfy more clippy.
This commit is contained in:
parent
9f5b68549a
commit
3e7408511e
@ -6,6 +6,7 @@ resolver = "2"
|
|||||||
authors = ["jhwgh1968", "Stephen Chung"]
|
authors = ["jhwgh1968", "Stephen Chung"]
|
||||||
description = "Procedural macros support package for Rhai, a scripting language and engine for Rust"
|
description = "Procedural macros support package for Rhai, a scripting language and engine for Rust"
|
||||||
keywords = ["rhai", "scripting", "scripting-engine", "scripting-language", "embedded", "plugin", "macros", "code-generation"]
|
keywords = ["rhai", "scripting", "scripting-engine", "scripting-language", "embedded", "plugin", "macros", "code-generation"]
|
||||||
|
categories = ["no-std", "embedded", "wasm", "parser-implementations"]
|
||||||
homepage = "https://rhai.rs/book/plugins/index.html"
|
homepage = "https://rhai.rs/book/plugins/index.html"
|
||||||
repository = "https://github.com/rhaiscript/rhai"
|
repository = "https://github.com/rhaiscript/rhai"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
@ -217,6 +217,7 @@ impl Engine {
|
|||||||
scope_may_be_changed: bool,
|
scope_may_be_changed: bool,
|
||||||
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
|
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
|
||||||
) -> ParseResult<&mut Self> {
|
) -> ParseResult<&mut Self> {
|
||||||
|
#[allow(clippy::wildcard_imports)]
|
||||||
use markers::*;
|
use markers::*;
|
||||||
|
|
||||||
let mut segments = StaticVec::<ImmutableString>::new();
|
let mut segments = StaticVec::<ImmutableString>::new();
|
||||||
|
@ -1012,7 +1012,20 @@ impl PartialEq for ASTNode<'_> {
|
|||||||
impl Eq for ASTNode<'_> {}
|
impl Eq for ASTNode<'_> {}
|
||||||
|
|
||||||
impl ASTNode<'_> {
|
impl ASTNode<'_> {
|
||||||
|
/// Is this [`ASTNode`] a [`Stmt`]?
|
||||||
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
|
pub const fn is_stmt(&self) -> bool {
|
||||||
|
matches!(self, Self::Stmt(..))
|
||||||
|
}
|
||||||
|
/// Is this [`ASTNode`] an [`Expr`]?
|
||||||
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
|
pub const fn is_expr(&self) -> bool {
|
||||||
|
matches!(self, Self::Expr(..))
|
||||||
|
}
|
||||||
/// Get the [`Position`] of this [`ASTNode`].
|
/// Get the [`Position`] of this [`ASTNode`].
|
||||||
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn position(&self) -> Position {
|
pub fn position(&self) -> Position {
|
||||||
match self {
|
match self {
|
||||||
|
@ -6,7 +6,7 @@ use std::prelude::v1::*;
|
|||||||
|
|
||||||
/// A type representing the access mode of a function.
|
/// A type representing the access mode of a function.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
#[cfg_attr(feature = "metadata", derive(serde::Serialize))]
|
#[cfg_attr(feature = "metadata", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "metadata", serde(rename_all = "camelCase"))]
|
#[cfg_attr(feature = "metadata", serde(rename_all = "camelCase"))]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum FnAccess {
|
pub enum FnAccess {
|
||||||
|
@ -926,10 +926,7 @@ impl Stmt {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_control_flow_break(&self) -> bool {
|
pub const fn is_control_flow_break(&self) -> bool {
|
||||||
match self {
|
matches!(self, Self::Return(..) | Self::BreakLoop(..))
|
||||||
Self::Return(..) | Self::BreakLoop(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Recursively walk this statement.
|
/// Recursively walk this statement.
|
||||||
/// Return `false` from the callback to terminate the walk.
|
/// Return `false` from the callback to terminate the walk.
|
||||||
|
@ -71,7 +71,7 @@ impl WhenTheHokmaSuppression {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn the_price_of_silence(self) {
|
pub fn the_price_of_silence(self) {
|
||||||
self.hokma.lock.store(self.state, Ordering::SeqCst);
|
self.hokma.lock.store(self.state, Ordering::SeqCst);
|
||||||
mem::forget(self)
|
mem::forget(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,14 +80,14 @@ impl Drop for WhenTheHokmaSuppression {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.hokma
|
self.hokma
|
||||||
.lock
|
.lock
|
||||||
.store(self.state.wrapping_add(2), Ordering::SeqCst)
|
.store(self.state.wrapping_add(2), Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn hokmalock(address: usize) -> &'static HokmaLock {
|
fn hokmalock(address: usize) -> &'static HokmaLock {
|
||||||
const LEN: usize = 787;
|
const LEN: usize = 787;
|
||||||
|
#[allow(clippy::declare_interior_mutable_const)]
|
||||||
const LCK: HokmaLock = HokmaLock::new();
|
const LCK: HokmaLock = HokmaLock::new();
|
||||||
static RECORDS: [HokmaLock; LEN] = [LCK; LEN];
|
static RECORDS: [HokmaLock; LEN] = [LCK; LEN];
|
||||||
|
|
||||||
@ -96,22 +96,16 @@ fn hokmalock(address: usize) -> &'static HokmaLock {
|
|||||||
|
|
||||||
// Safety: lol, there is a reason its called `SusLock<T>`
|
// Safety: lol, there is a reason its called `SusLock<T>`
|
||||||
#[must_use]
|
#[must_use]
|
||||||
struct SusLock<T>
|
struct SusLock<T: 'static> {
|
||||||
where
|
|
||||||
T: 'static,
|
|
||||||
{
|
|
||||||
initialized: AtomicBool,
|
initialized: AtomicBool,
|
||||||
data: UnsafeCell<MaybeUninit<T>>,
|
data: UnsafeCell<MaybeUninit<T>>,
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> SusLock<T>
|
impl<T: 'static> SusLock<T> {
|
||||||
where
|
|
||||||
T: 'static,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn new() -> SusLock<T> {
|
pub const fn new() -> Self {
|
||||||
SusLock {
|
Self {
|
||||||
initialized: AtomicBool::new(false),
|
initialized: AtomicBool::new(false),
|
||||||
data: UnsafeCell::new(MaybeUninit::uninit()),
|
data: UnsafeCell::new(MaybeUninit::uninit()),
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
@ -131,7 +125,7 @@ where
|
|||||||
// we forgo the optimistic read, because we don't really care
|
// we forgo the optimistic read, because we don't really care
|
||||||
let guard = hokma.write();
|
let guard = hokma.write();
|
||||||
let cast: *const T = self.data.get().cast();
|
let cast: *const T = self.data.get().cast();
|
||||||
let val = unsafe { mem::transmute::<*const T, &'static T>(cast) };
|
let val = unsafe { &*cast.cast::<T>() };
|
||||||
guard.the_price_of_silence();
|
guard.the_price_of_silence();
|
||||||
Some(val)
|
Some(val)
|
||||||
} else {
|
} else {
|
||||||
@ -143,7 +137,7 @@ where
|
|||||||
pub fn get_or_init(&self, f: impl FnOnce() -> T) -> &'static T {
|
pub fn get_or_init(&self, f: impl FnOnce() -> T) -> &'static T {
|
||||||
if !self.initialized.load(Ordering::SeqCst) {
|
if !self.initialized.load(Ordering::SeqCst) {
|
||||||
self.initialized.store(true, Ordering::SeqCst);
|
self.initialized.store(true, Ordering::SeqCst);
|
||||||
let hokma = hokmalock(unsafe { mem::transmute(self.data.get()) });
|
let hokma = hokmalock(self.data.get() as usize);
|
||||||
hokma.write();
|
hokma.write();
|
||||||
unsafe {
|
unsafe {
|
||||||
self.data.get().write(MaybeUninit::new(f()));
|
self.data.get().write(MaybeUninit::new(f()));
|
||||||
@ -163,14 +157,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T: Sync + Send> Sync for SusLock<T> where T: 'static {}
|
unsafe impl<T: Sync + Send> Sync for SusLock<T> {}
|
||||||
unsafe impl<T: Send> Send for SusLock<T> where T: 'static {}
|
unsafe impl<T: Send> Send for SusLock<T> {}
|
||||||
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for SusLock<T> {}
|
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for SusLock<T> {}
|
||||||
|
|
||||||
impl<T> Drop for SusLock<T>
|
impl<T: 'static> Drop for SusLock<T> {
|
||||||
where
|
|
||||||
T: 'static,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.initialized.load(Ordering::SeqCst) {
|
if self.initialized.load(Ordering::SeqCst) {
|
||||||
|
@ -259,7 +259,7 @@ impl Engine {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||||
let offset = index as usize;
|
let offset = index as usize;
|
||||||
(
|
(
|
||||||
s.chars().nth(offset).ok_or_else(|| {
|
s.chars().nth(offset).ok_or_else(|| {
|
||||||
|
@ -471,14 +471,11 @@ impl Engine {
|
|||||||
|
|
||||||
let event = match global.debugger.status {
|
let event = match global.debugger.status {
|
||||||
DebuggerStatus::Init => Some(DebuggerEvent::Start),
|
DebuggerStatus::Init => Some(DebuggerEvent::Start),
|
||||||
DebuggerStatus::CONTINUE => None,
|
DebuggerStatus::NEXT if node.is_stmt() => Some(DebuggerEvent::Step),
|
||||||
DebuggerStatus::NEXT if matches!(node, ASTNode::Stmt(..)) => Some(DebuggerEvent::Step),
|
DebuggerStatus::INTO if node.is_expr() => Some(DebuggerEvent::Step),
|
||||||
DebuggerStatus::NEXT => None,
|
|
||||||
DebuggerStatus::INTO if matches!(node, ASTNode::Expr(..)) => Some(DebuggerEvent::Step),
|
|
||||||
DebuggerStatus::INTO => None,
|
|
||||||
DebuggerStatus::STEP => Some(DebuggerEvent::Step),
|
DebuggerStatus::STEP => Some(DebuggerEvent::Step),
|
||||||
DebuggerStatus::FunctionExit(..) => None,
|
|
||||||
DebuggerStatus::Terminate => Some(DebuggerEvent::End),
|
DebuggerStatus::Terminate => Some(DebuggerEvent::End),
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = match event {
|
let event = match event {
|
||||||
|
@ -93,6 +93,7 @@ mod logic_functions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[allow(clippy::cast_precision_loss)]
|
||||||
#[export_module]
|
#[export_module]
|
||||||
mod f32_functions {
|
mod f32_functions {
|
||||||
use crate::INT;
|
use crate::INT;
|
||||||
@ -148,6 +149,7 @@ mod f32_functions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[allow(clippy::cast_precision_loss)]
|
||||||
#[export_module]
|
#[export_module]
|
||||||
mod f64_functions {
|
mod f64_functions {
|
||||||
use crate::INT;
|
use crate::INT;
|
||||||
|
@ -145,6 +145,7 @@ mod int_functions {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||||
INT::from_str_radix(string.trim(), radix as u32).map_err(|err| {
|
INT::from_str_radix(string.trim(), radix as u32).map_err(|err| {
|
||||||
ERR::ErrorArithmetic(
|
ERR::ErrorArithmetic(
|
||||||
format!("Error parsing integer number '{string}': {err}"),
|
format!("Error parsing integer number '{string}': {err}"),
|
||||||
@ -313,6 +314,7 @@ mod float_functions {
|
|||||||
/// Convert the floating-point number into an integer.
|
/// Convert the floating-point number into an integer.
|
||||||
#[rhai_fn(name = "to_int", return_raw)]
|
#[rhai_fn(name = "to_int", return_raw)]
|
||||||
pub fn f32_to_int(x: f32) -> RhaiResultOf<INT> {
|
pub fn f32_to_int(x: f32) -> RhaiResultOf<INT> {
|
||||||
|
#[allow(clippy::cast_precision_loss)]
|
||||||
if cfg!(not(feature = "unchecked")) && (x > (INT::MAX as f32) || x < (INT::MIN as f32)) {
|
if cfg!(not(feature = "unchecked")) && (x > (INT::MAX as f32) || x < (INT::MIN as f32)) {
|
||||||
Err(
|
Err(
|
||||||
ERR::ErrorArithmetic(format!("Integer overflow: to_int({x})"), Position::NONE)
|
ERR::ErrorArithmetic(format!("Integer overflow: to_int({x})"), Position::NONE)
|
||||||
@ -325,6 +327,7 @@ mod float_functions {
|
|||||||
/// Convert the floating-point number into an integer.
|
/// Convert the floating-point number into an integer.
|
||||||
#[rhai_fn(name = "to_int", return_raw)]
|
#[rhai_fn(name = "to_int", return_raw)]
|
||||||
pub fn f64_to_int(x: f64) -> RhaiResultOf<INT> {
|
pub fn f64_to_int(x: f64) -> RhaiResultOf<INT> {
|
||||||
|
#[allow(clippy::cast_precision_loss)]
|
||||||
if cfg!(not(feature = "unchecked")) && (x > (INT::MAX as f64) || x < (INT::MIN as f64)) {
|
if cfg!(not(feature = "unchecked")) && (x > (INT::MAX as f64) || x < (INT::MIN as f64)) {
|
||||||
Err(
|
Err(
|
||||||
ERR::ErrorArithmetic(format!("Integer overflow: to_int({x})"), Position::NONE)
|
ERR::ErrorArithmetic(format!("Integer overflow: to_int({x})"), Position::NONE)
|
||||||
@ -357,7 +360,7 @@ mod float_functions {
|
|||||||
#[cfg(not(feature = "f32_float"))]
|
#[cfg(not(feature = "f32_float"))]
|
||||||
#[rhai_fn(name = "to_float")]
|
#[rhai_fn(name = "to_float")]
|
||||||
pub fn f32_to_f64(x: f32) -> f64 {
|
pub fn f32_to_f64(x: f32) -> f64 {
|
||||||
x as f64
|
x.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,6 +481,7 @@ mod decimal_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_sign_loss)]
|
||||||
Ok(x.round_dp(digits as u32))
|
Ok(x.round_dp(digits as u32))
|
||||||
}
|
}
|
||||||
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
||||||
@ -495,6 +499,7 @@ mod decimal_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_sign_loss)]
|
||||||
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::AwayFromZero))
|
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::AwayFromZero))
|
||||||
}
|
}
|
||||||
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
||||||
@ -512,6 +517,7 @@ mod decimal_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_sign_loss)]
|
||||||
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::ToZero))
|
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::ToZero))
|
||||||
}
|
}
|
||||||
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
||||||
@ -529,6 +535,7 @@ mod decimal_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_sign_loss)]
|
||||||
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::MidpointAwayFromZero))
|
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::MidpointAwayFromZero))
|
||||||
}
|
}
|
||||||
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
/// Round the decimal number to the specified number of `digits` after the decimal point and return it.
|
||||||
@ -546,6 +553,7 @@ mod decimal_functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_sign_loss)]
|
||||||
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::MidpointTowardZero))
|
Ok(x.round_dp_with_strategy(digits as u32, RoundingStrategy::MidpointTowardZero))
|
||||||
}
|
}
|
||||||
/// Convert the decimal number into an integer.
|
/// Convert the decimal number into an integer.
|
||||||
@ -563,14 +571,15 @@ mod decimal_functions {
|
|||||||
return Some(n);
|
return Some(n);
|
||||||
});
|
});
|
||||||
|
|
||||||
match n {
|
n.map_or_else(
|
||||||
Some(n) => Ok(n),
|
|| {
|
||||||
_ => Err(ERR::ErrorArithmetic(
|
Err(
|
||||||
format!("Integer overflow: to_int({x})"),
|
ERR::ErrorArithmetic(format!("Integer overflow: to_int({x})"), Position::NONE)
|
||||||
Position::NONE,
|
.into(),
|
||||||
)
|
)
|
||||||
.into()),
|
},
|
||||||
}
|
|n| Ok(n),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/// Return the integral part of the decimal number.
|
/// Return the integral part of the decimal number.
|
||||||
#[rhai_fn(name = "int", get = "int")]
|
#[rhai_fn(name = "int", get = "int")]
|
||||||
|
@ -247,9 +247,10 @@ mod string_functions {
|
|||||||
/// Clear the string, making it empty.
|
/// Clear the string, making it empty.
|
||||||
pub fn clear(string: &mut ImmutableString) {
|
pub fn clear(string: &mut ImmutableString) {
|
||||||
if !string.is_empty() {
|
if !string.is_empty() {
|
||||||
match string.get_mut() {
|
if let Some(s) = string.get_mut() {
|
||||||
Some(s) => s.clear(),
|
s.clear()
|
||||||
_ => *string = ImmutableString::new(),
|
} else {
|
||||||
|
*string = ImmutableString::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,6 +274,7 @@ mod string_functions {
|
|||||||
/// ```
|
/// ```
|
||||||
pub fn truncate(string: &mut ImmutableString, len: INT) {
|
pub fn truncate(string: &mut ImmutableString, len: INT) {
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
|
#[allow(clippy::cast_sign_loss)]
|
||||||
let len = len.min(MAX_USIZE_INT) as usize;
|
let len = len.min(MAX_USIZE_INT) as usize;
|
||||||
let chars: StaticVec<_> = string.chars().collect();
|
let chars: StaticVec<_> = string.chars().collect();
|
||||||
let copy = string.make_mut();
|
let copy = string.make_mut();
|
||||||
@ -294,20 +296,17 @@ mod string_functions {
|
|||||||
/// print(text); // prints "hello"
|
/// print(text); // prints "hello"
|
||||||
/// ```
|
/// ```
|
||||||
pub fn trim(string: &mut ImmutableString) {
|
pub fn trim(string: &mut ImmutableString) {
|
||||||
match string.get_mut() {
|
if let Some(s) = string.get_mut() {
|
||||||
Some(s) => {
|
let trimmed = s.trim();
|
||||||
let trimmed = s.trim();
|
|
||||||
|
|
||||||
if trimmed != s {
|
if trimmed != s {
|
||||||
*s = trimmed.into();
|
*s = trimmed.into();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => {
|
} else {
|
||||||
let trimmed = string.trim();
|
let trimmed = string.trim();
|
||||||
|
|
||||||
if trimmed != string {
|
if trimmed != string {
|
||||||
*string = trimmed.into();
|
*string = trimmed.into();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ pub struct ParseState<'e> {
|
|||||||
pub block_stack_len: usize,
|
pub block_stack_len: usize,
|
||||||
/// Tracks a list of external variables (variables that are not explicitly declared in the scope).
|
/// Tracks a list of external variables (variables that are not explicitly declared in the scope).
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
pub external_vars: Vec<crate::ast::Ident>,
|
pub external_vars: Vec<Ident>,
|
||||||
/// An indicator that disables variable capturing into externals one single time
|
/// An indicator that disables variable capturing into externals one single time
|
||||||
/// up until the nearest consumed Identifier token.
|
/// up until the nearest consumed Identifier token.
|
||||||
/// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the variable.
|
/// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the variable.
|
||||||
@ -201,7 +201,7 @@ impl<'e> ParseState<'e> {
|
|||||||
if self.allow_capture {
|
if self.allow_capture {
|
||||||
if !is_func_name && index == 0 && !self.external_vars.iter().any(|v| v.as_str() == name)
|
if !is_func_name && index == 0 && !self.external_vars.iter().any(|v| v.as_str() == name)
|
||||||
{
|
{
|
||||||
self.external_vars.push(crate::ast::Ident {
|
self.external_vars.push(Ident {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
pos: _pos,
|
pos: _pos,
|
||||||
});
|
});
|
||||||
@ -1479,8 +1479,10 @@ impl Engine {
|
|||||||
let (expr, func) = result?;
|
let (expr, func) = result?;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
new_state.external_vars.iter().try_for_each(
|
new_state
|
||||||
|crate::ast::Ident { name, pos }| {
|
.external_vars
|
||||||
|
.iter()
|
||||||
|
.try_for_each(|Ident { name, pos }| {
|
||||||
let (index, is_func) = state.access_var(name, lib, *pos);
|
let (index, is_func) = state.access_var(name, lib, *pos);
|
||||||
|
|
||||||
if !is_func
|
if !is_func
|
||||||
@ -1496,8 +1498,7 @@ impl Engine {
|
|||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
},
|
})?;
|
||||||
)?;
|
|
||||||
|
|
||||||
let hash_script = calc_fn_hash(None, &func.name, func.params.len());
|
let hash_script = calc_fn_hash(None, &func.name, func.params.len());
|
||||||
lib.insert(hash_script, func.into());
|
lib.insert(hash_script, func.into());
|
||||||
@ -3662,9 +3663,11 @@ impl Engine {
|
|||||||
parent: &mut ParseState,
|
parent: &mut ParseState,
|
||||||
lib: &FnLib,
|
lib: &FnLib,
|
||||||
fn_expr: Expr,
|
fn_expr: Expr,
|
||||||
externals: StaticVec<crate::ast::Ident>,
|
externals: StaticVec<Ident>,
|
||||||
pos: Position,
|
pos: Position,
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
|
use crate::{ast::Namespace, 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() {
|
||||||
return fn_expr;
|
return fn_expr;
|
||||||
@ -3675,25 +3678,18 @@ impl Engine {
|
|||||||
|
|
||||||
args.push(fn_expr);
|
args.push(fn_expr);
|
||||||
|
|
||||||
args.extend(
|
args.extend(externals.iter().cloned().map(|Ident { name, pos }| {
|
||||||
externals
|
let (index, is_func) = parent.access_var(&name, lib, pos);
|
||||||
.iter()
|
let idx = match index {
|
||||||
.cloned()
|
Some(n) if !is_func && n.get() <= u8::MAX as usize => NonZeroU8::new(n.get() as u8),
|
||||||
.map(|crate::ast::Ident { name, pos }| {
|
_ => None,
|
||||||
let (index, is_func) = parent.access_var(&name, lib, pos);
|
};
|
||||||
let idx = match index {
|
Expr::Variable((index, Namespace::default(), 0, name).into(), idx, pos)
|
||||||
Some(n) if !is_func && n.get() <= u8::MAX as usize => {
|
}));
|
||||||
NonZeroU8::new(n.get() as u8)
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
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: Default::default(),
|
namespace: Namespace::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,
|
||||||
@ -3712,15 +3708,15 @@ impl Engine {
|
|||||||
statements.push(Stmt::Share(
|
statements.push(Stmt::Share(
|
||||||
externals
|
externals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|crate::ast::Ident { name, pos }| {
|
.map(|Ident { name, pos }| {
|
||||||
let (index, _) = parent.access_var(&name, lib, pos);
|
let (index, _) = parent.access_var(&name, lib, pos);
|
||||||
(name, index, pos)
|
(name, index, pos)
|
||||||
})
|
})
|
||||||
.collect::<crate::FnArgsVec<_>>()
|
.collect::<FnArgsVec<_>>()
|
||||||
.into(),
|
.into(),
|
||||||
));
|
));
|
||||||
statements.push(Stmt::Expr(expr.into()));
|
statements.push(Stmt::Expr(expr.into()));
|
||||||
Expr::Stmt(crate::ast::StmtBlock::new(statements, pos, Position::NONE).into())
|
Expr::Stmt(StmtBlock::new(statements, pos, Position::NONE).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an anonymous function definition.
|
/// Parse an anonymous function definition.
|
||||||
@ -3744,7 +3740,7 @@ impl Engine {
|
|||||||
match input.next().expect(NEVER_ENDS) {
|
match input.next().expect(NEVER_ENDS) {
|
||||||
(Token::Pipe, ..) => break,
|
(Token::Pipe, ..) => break,
|
||||||
(Token::Identifier(s), pos) => {
|
(Token::Identifier(s), pos) => {
|
||||||
if params_list.iter().any(|p| p.as_str() == &*s) {
|
if params_list.iter().any(|p| p.as_str() == *s) {
|
||||||
return Err(
|
return Err(
|
||||||
PERR::FnDuplicatedParam(String::new(), s.to_string()).into_err(pos)
|
PERR::FnDuplicatedParam(String::new(), s.to_string()).into_err(pos)
|
||||||
);
|
);
|
||||||
@ -3789,11 +3785,7 @@ impl Engine {
|
|||||||
let externals: StaticVec<_> = state.external_vars.iter().cloned().collect();
|
let externals: StaticVec<_> = state.external_vars.iter().cloned().collect();
|
||||||
|
|
||||||
let mut params = StaticVec::with_capacity(params_list.len() + externals.len());
|
let mut params = StaticVec::with_capacity(params_list.len() + externals.len());
|
||||||
params.extend(
|
params.extend(externals.iter().map(|Ident { name, .. }| name.clone()));
|
||||||
externals
|
|
||||||
.iter()
|
|
||||||
.map(|crate::ast::Ident { name, .. }| name.clone()),
|
|
||||||
);
|
|
||||||
|
|
||||||
(params, externals)
|
(params, externals)
|
||||||
};
|
};
|
||||||
|
@ -174,10 +174,10 @@ pub fn gen_metadata_to_json(
|
|||||||
global.modules.insert(name, m.as_ref().into());
|
global.modules.insert(name, m.as_ref().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let exclude_flags = if !include_standard_packages {
|
let exclude_flags = if include_standard_packages {
|
||||||
ModuleFlags::STANDARD_LIB
|
|
||||||
} else {
|
|
||||||
ModuleFlags::empty()
|
ModuleFlags::empty()
|
||||||
|
} else {
|
||||||
|
ModuleFlags::STANDARD_LIB
|
||||||
};
|
};
|
||||||
|
|
||||||
engine
|
engine
|
||||||
|
@ -590,6 +590,7 @@ pub enum Token {
|
|||||||
impl fmt::Display for Token {
|
impl fmt::Display for Token {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -619,6 +620,7 @@ impl Token {
|
|||||||
/// Is the token a literal symbol?
|
/// Is the token a literal symbol?
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_literal(&self) -> bool {
|
pub const fn is_literal(&self) -> bool {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -648,6 +650,7 @@ impl Token {
|
|||||||
/// Panics if the token is not a literal symbol.
|
/// Panics if the token is not a literal symbol.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn literal_syntax(&self) -> &'static str {
|
pub const fn literal_syntax(&self) -> &'static str {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -824,6 +827,7 @@ impl Token {
|
|||||||
/// Reverse lookup a symbol token from a piece of syntax.
|
/// Reverse lookup a symbol token from a piece of syntax.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn lookup_symbol_from_syntax(syntax: &str) -> Option<Self> {
|
pub fn lookup_symbol_from_syntax(syntax: &str) -> Option<Self> {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
Some(match syntax {
|
Some(match syntax {
|
||||||
@ -963,6 +967,7 @@ impl Token {
|
|||||||
/// (not sure about `fn` name).
|
/// (not sure about `fn` name).
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_next_unary(&self) -> bool {
|
pub const fn is_next_unary(&self) -> bool {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -1034,6 +1039,7 @@ impl Token {
|
|||||||
/// Get the precedence number of the token.
|
/// Get the precedence number of the token.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn precedence(&self) -> Option<Precedence> {
|
pub const fn precedence(&self) -> Option<Precedence> {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
Precedence::new(match self {
|
Precedence::new(match self {
|
||||||
@ -1066,6 +1072,7 @@ impl Token {
|
|||||||
/// Does an expression bind to the right (instead of left)?
|
/// Does an expression bind to the right (instead of left)?
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_bind_right(&self) -> bool {
|
pub const fn is_bind_right(&self) -> bool {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -1079,6 +1086,7 @@ impl Token {
|
|||||||
/// Is this token a standard symbol used in the language?
|
/// Is this token a standard symbol used in the language?
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_standard_symbol(&self) -> bool {
|
pub const fn is_standard_symbol(&self) -> bool {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -1105,6 +1113,7 @@ impl Token {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_standard_keyword(&self) -> bool {
|
pub const fn is_standard_keyword(&self) -> bool {
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
@ -1501,13 +1510,13 @@ pub fn get_next_token(
|
|||||||
|
|
||||||
/// Test if the given character is a hex character.
|
/// Test if the given character is a hex character.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_hex_digit(c: char) -> bool {
|
const fn is_hex_digit(c: char) -> bool {
|
||||||
matches!(c, 'a'..='f' | 'A'..='F' | '0'..='9')
|
matches!(c, 'a'..='f' | 'A'..='F' | '0'..='9')
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the given character is a numeric digit.
|
/// Test if the given character is a numeric digit.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_numeric_digit(c: char) -> bool {
|
const fn is_numeric_digit(c: char) -> bool {
|
||||||
matches!(c, '0'..='9')
|
matches!(c, '0'..='9')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1687,21 +1696,8 @@ fn get_next_token_inner(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Parse number
|
// Parse number
|
||||||
return Some((
|
let token = radix_base.map_or_else(
|
||||||
if let Some(radix) = radix_base {
|
|| {
|
||||||
let result = &result[2..];
|
|
||||||
|
|
||||||
UNSIGNED_INT::from_str_radix(&result, radix)
|
|
||||||
.map(|v| v as INT)
|
|
||||||
.map_or_else(
|
|
||||||
|_| {
|
|
||||||
Token::LexError(
|
|
||||||
LERR::MalformedNumber(result.to_string()).into(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
Token::IntegerConstant,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
let num = INT::from_str(&result).map(Token::IntegerConstant);
|
let num = INT::from_str(&result).map(Token::IntegerConstant);
|
||||||
|
|
||||||
// If integer parsing is unnecessary, try float instead
|
// If integer parsing is unnecessary, try float instead
|
||||||
@ -1730,8 +1726,23 @@ fn get_next_token_inner(
|
|||||||
Token::LexError(LERR::MalformedNumber(result.to_string()).into())
|
Token::LexError(LERR::MalformedNumber(result.to_string()).into())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
num_pos,
|
|radix| {
|
||||||
));
|
let result = &result[2..];
|
||||||
|
|
||||||
|
UNSIGNED_INT::from_str_radix(result, radix)
|
||||||
|
.map(|v| v as INT)
|
||||||
|
.map_or_else(
|
||||||
|
|_| {
|
||||||
|
Token::LexError(
|
||||||
|
LERR::MalformedNumber(result.to_string()).into(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
Token::IntegerConstant,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return Some((token, num_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
// letter or underscore ...
|
// letter or underscore ...
|
||||||
@ -1760,7 +1771,7 @@ fn get_next_token_inner(
|
|||||||
Some('\r') => {
|
Some('\r') => {
|
||||||
eat_next(stream, pos);
|
eat_next(stream, pos);
|
||||||
// `\r\n
|
// `\r\n
|
||||||
if let Some('\n') = stream.peek_next() {
|
if stream.peek_next() == Some('\n') {
|
||||||
eat_next(stream, pos);
|
eat_next(stream, pos);
|
||||||
}
|
}
|
||||||
pos.new_line();
|
pos.new_line();
|
||||||
@ -1788,7 +1799,7 @@ fn get_next_token_inner(
|
|||||||
// ' - character literal
|
// ' - character literal
|
||||||
('\'', '\'') => {
|
('\'', '\'') => {
|
||||||
return Some((
|
return Some((
|
||||||
Token::LexError(LERR::MalformedChar("".to_string()).into()),
|
Token::LexError(LERR::MalformedChar(String::new()).into()),
|
||||||
start_pos,
|
start_pos,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -1941,7 +1952,7 @@ fn get_next_token_inner(
|
|||||||
while let Some(c) = stream.get_next() {
|
while let Some(c) = stream.get_next() {
|
||||||
if c == '\r' {
|
if c == '\r' {
|
||||||
// \r\n
|
// \r\n
|
||||||
if let Some('\n') = stream.peek_next() {
|
if stream.peek_next() == Some('\n') {
|
||||||
eat_next(stream, pos);
|
eat_next(stream, pos);
|
||||||
}
|
}
|
||||||
pos.new_line();
|
pos.new_line();
|
||||||
|
@ -105,7 +105,7 @@ impl Add<BloomFilterU64> for &BloomFilterU64 {
|
|||||||
impl AddAssign<Self> for BloomFilterU64 {
|
impl AddAssign<Self> for BloomFilterU64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
*self += &rhs
|
*self += &rhs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicWriteLockInner::Reference(ref reference) => *reference,
|
DynamicWriteLockInner::Reference(ref reference) => reference,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
DynamicWriteLockInner::Guard(ref guard) => guard.downcast_ref().expect(CHECKED),
|
DynamicWriteLockInner::Guard(ref guard) => guard.downcast_ref().expect(CHECKED),
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
DynamicWriteLockInner::Reference(ref mut reference) => *reference,
|
DynamicWriteLockInner::Reference(ref mut reference) => reference,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
DynamicWriteLockInner::Guard(ref mut guard) => guard.downcast_mut().expect(CHECKED),
|
DynamicWriteLockInner::Guard(ref mut guard) => guard.downcast_mut().expect(CHECKED),
|
||||||
}
|
}
|
||||||
@ -640,6 +640,7 @@ impl fmt::Debug for Dynamic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::enum_glob_use)]
|
||||||
use AccessMode::*;
|
use AccessMode::*;
|
||||||
|
|
||||||
impl Clone for Dynamic {
|
impl Clone for Dynamic {
|
||||||
@ -1088,7 +1089,7 @@ impl Dynamic {
|
|||||||
pub fn from<T: Variant + Clone>(value: T) -> Self {
|
pub fn from<T: Variant + Clone>(value: T) -> Self {
|
||||||
// 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.
|
||||||
|
|
||||||
reify!(value, |v: Dynamic| return v);
|
reify!(value, |v: Self| return v);
|
||||||
reify!(value, |v: INT| return v.into());
|
reify!(value, |v: INT| return v.into());
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
@ -1187,7 +1188,7 @@ impl Dynamic {
|
|||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
self.flatten_in_place();
|
self.flatten_in_place();
|
||||||
|
|
||||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
if TypeId::of::<T>() == TypeId::of::<Self>() {
|
||||||
return Some(reify!(self => T));
|
return Some(reify!(self => T));
|
||||||
}
|
}
|
||||||
if TypeId::of::<T>() == TypeId::of::<()>() {
|
if TypeId::of::<T>() == TypeId::of::<()>() {
|
||||||
@ -1309,7 +1310,7 @@ impl Dynamic {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn cast<T: Any + Clone>(self) -> T {
|
pub fn cast<T: Any + Clone>(self) -> T {
|
||||||
// Bail out early if the return type needs no cast
|
// Bail out early if the return type needs no cast
|
||||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
if TypeId::of::<T>() == TypeId::of::<Self>() {
|
||||||
return reify!(self => T);
|
return reify!(self => T);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1408,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"))]
|
||||||
|value| value.into_inner(),
|
crate::Locked::into_inner,
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
|value| value.into_inner().unwrap(),
|
crate::Locked::into_inner().unwrap(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -299,10 +299,7 @@ impl EvalAltResult {
|
|||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_pseudo_error(&self) -> bool {
|
pub const fn is_pseudo_error(&self) -> bool {
|
||||||
match self {
|
matches!(self, Self::LoopBreak(..) | Self::Return(..))
|
||||||
Self::LoopBreak(..) | Self::Return(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Can this error be caught?
|
/// Can this error be caught?
|
||||||
#[cold]
|
#[cold]
|
||||||
@ -357,20 +354,17 @@ impl EvalAltResult {
|
|||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_system_exception(&self) -> bool {
|
pub const fn is_system_exception(&self) -> bool {
|
||||||
match self {
|
matches!(
|
||||||
Self::ErrorSystem(..) => true,
|
self,
|
||||||
Self::ErrorParsing(..) => true,
|
Self::ErrorSystem(..)
|
||||||
|
| Self::ErrorParsing(..)
|
||||||
Self::ErrorCustomSyntax(..)
|
| Self::ErrorCustomSyntax(..)
|
||||||
| Self::ErrorTooManyOperations(..)
|
| Self::ErrorTooManyOperations(..)
|
||||||
| Self::ErrorTooManyModules(..)
|
| Self::ErrorTooManyModules(..)
|
||||||
| Self::ErrorStackOverflow(..)
|
| Self::ErrorStackOverflow(..)
|
||||||
| Self::ErrorDataTooLarge(..) => true,
|
| Self::ErrorDataTooLarge(..)
|
||||||
|
| Self::ErrorTerminated(..)
|
||||||
Self::ErrorTerminated(..) => true,
|
)
|
||||||
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Get the [position][Position] of this error.
|
/// Get the [position][Position] of this error.
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
@ -459,7 +453,6 @@ impl EvalAltResult {
|
|||||||
/// Unwrap this error and get the very base error.
|
/// Unwrap this error and get the very base error.
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
|
||||||
pub fn unwrap_inner(&self) -> &Self {
|
pub fn unwrap_inner(&self) -> &Self {
|
||||||
match self {
|
match self {
|
||||||
Self::ErrorInFunctionCall(.., err, _) | Self::ErrorInModule(.., err, _) => {
|
Self::ErrorInFunctionCall(.., err, _) | Self::ErrorInModule(.., err, _) => {
|
||||||
|
@ -14,7 +14,7 @@ use num_traits::float::FloatCore as Float;
|
|||||||
/// A type that wraps a floating-point number and implements [`Hash`].
|
/// A type that wraps a floating-point number and implements [`Hash`].
|
||||||
///
|
///
|
||||||
/// Not available under `no_float`.
|
/// Not available under `no_float`.
|
||||||
#[derive(Clone, Copy, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Eq, PartialEq, PartialOrd)]
|
||||||
pub struct FloatWrapper<F>(F);
|
pub struct FloatWrapper<F>(F);
|
||||||
|
|
||||||
impl Hash for FloatWrapper<crate::FLOAT> {
|
impl Hash for FloatWrapper<crate::FLOAT> {
|
||||||
|
@ -147,7 +147,6 @@ impl FromStr for ImmutableString {
|
|||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let s: SmartString = s.into();
|
let s: SmartString = s.into();
|
||||||
Ok(Self(s.into()))
|
Ok(Self(s.into()))
|
||||||
|
@ -175,7 +175,6 @@ impl ParseErrorType {
|
|||||||
/// Make a [`ParseError`] using the current type and position.
|
/// Make a [`ParseError`] using the current type and position.
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
|
||||||
pub(crate) fn into_err(self, pos: Position) -> ParseError {
|
pub(crate) fn into_err(self, pos: Position) -> ParseError {
|
||||||
ParseError(self.into(), pos)
|
ParseError(self.into(), pos)
|
||||||
}
|
}
|
||||||
@ -299,7 +298,6 @@ impl ParseError {
|
|||||||
/// Get the [type][ParseErrorType] of this parse error.
|
/// Get the [type][ParseErrorType] of this parse error.
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
|
||||||
pub const fn err_type(&self) -> &ParseErrorType {
|
pub const fn err_type(&self) -> &ParseErrorType {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
@ -316,7 +314,7 @@ impl From<ParseErrorType> for RhaiError {
|
|||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn from(err: ParseErrorType) -> Self {
|
fn from(err: ParseErrorType) -> Self {
|
||||||
Box::new(err.into())
|
Self::new(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +330,7 @@ impl From<ParseError> for RhaiError {
|
|||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn from(err: ParseError) -> Self {
|
fn from(err: ParseError) -> Self {
|
||||||
Box::new(err.into())
|
Self::new(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user