Satisfy Clippy.
This commit is contained in:
@@ -72,7 +72,7 @@ impl Caches {
|
||||
/// Push an empty function resolution cache onto the stack and make it current.
|
||||
#[inline(always)]
|
||||
pub fn push_fn_resolution_cache(&mut self) {
|
||||
self.0.push(Default::default());
|
||||
self.0.push(FnResolutionCache::default());
|
||||
}
|
||||
/// Rewind the function resolution caches stack to a particular size.
|
||||
#[inline(always)]
|
||||
|
@@ -168,6 +168,7 @@ impl Engine {
|
||||
ERR::ErrorBitFieldBounds(crate::INT_BITS, end, idx_pos).into()
|
||||
})?;
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
if end <= start {
|
||||
(0, 0)
|
||||
} else if end == crate::INT_BITS && start == 0 {
|
||||
@@ -193,6 +194,7 @@ impl Engine {
|
||||
ERR::ErrorBitFieldBounds(crate::INT_BITS, end, idx_pos).into()
|
||||
})?;
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
if end < start {
|
||||
(0, 0)
|
||||
} else if end == crate::INT_BITS - 1 && start == 0 {
|
||||
@@ -237,6 +239,7 @@ impl Engine {
|
||||
Ok(Target::Bit {
|
||||
source: target,
|
||||
value: bit_value.into(),
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
bit: bit as u8,
|
||||
})
|
||||
}
|
||||
@@ -249,12 +252,14 @@ impl Engine {
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, idx_pos))?;
|
||||
|
||||
let (ch, offset) = if index >= 0 {
|
||||
#[allow(clippy::absurd_extreme_comparisons)]
|
||||
if index >= crate::MAX_USIZE_INT {
|
||||
return Err(
|
||||
ERR::ErrorStringBounds(s.chars().count(), index, idx_pos).into()
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
let offset = index as usize;
|
||||
(
|
||||
s.chars().nth(offset).ok_or_else(|| {
|
||||
@@ -265,12 +270,13 @@ impl Engine {
|
||||
} else {
|
||||
let abs_index = index.unsigned_abs();
|
||||
|
||||
if abs_index as u64 > usize::MAX as u64 {
|
||||
if abs_index > usize::MAX as u64 {
|
||||
return Err(
|
||||
ERR::ErrorStringBounds(s.chars().count(), index, idx_pos).into()
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
let offset = abs_index as usize;
|
||||
(
|
||||
// Count from end if negative
|
||||
|
@@ -59,7 +59,7 @@ impl Dynamic {
|
||||
}
|
||||
Union::Str(ref s, ..) => (0, 0, s.len()),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(..) if _top => self.read_lock::<Dynamic>().unwrap().calc_data_sizes(true),
|
||||
Union::Shared(..) if _top => self.read_lock::<Self>().unwrap().calc_data_sizes(true),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(..) => {
|
||||
unreachable!("shared values discovered within data: {}", self)
|
||||
|
@@ -193,7 +193,7 @@ impl BreakPoint {
|
||||
/// Is this [`BreakPoint`] enabled?
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
pub const fn is_enabled(&self) -> bool {
|
||||
match self {
|
||||
#[cfg(not(feature = "no_position"))]
|
||||
Self::AtPosition { enabled, .. } => *enabled,
|
||||
@@ -268,7 +268,7 @@ impl Debugger {
|
||||
/// Create a new [`Debugger`].
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn new(status: DebuggerStatus, state: Dynamic) -> Self {
|
||||
pub const fn new(status: DebuggerStatus, state: Dynamic) -> Self {
|
||||
Self {
|
||||
status,
|
||||
break_points: Vec::new(),
|
||||
@@ -297,7 +297,7 @@ impl Debugger {
|
||||
pos: Position,
|
||||
) {
|
||||
self.call_stack.push(CallStackFrame {
|
||||
fn_name: fn_name.into(),
|
||||
fn_name,
|
||||
args,
|
||||
source,
|
||||
pos,
|
||||
|
@@ -156,7 +156,7 @@ impl Engine {
|
||||
.any(|(_, _, f, ..)| f == v.3.as_str()) =>
|
||||
{
|
||||
let val: Dynamic =
|
||||
crate::FnPtr::new_unchecked(v.3.as_str(), Default::default()).into();
|
||||
crate::FnPtr::new_unchecked(v.3.as_str(), crate::StaticVec::default()).into();
|
||||
return Ok(val.into());
|
||||
}
|
||||
Expr::Variable(v, None, ..) => v.0.map_or(0, NonZeroUsize::get),
|
||||
@@ -186,14 +186,20 @@ impl Engine {
|
||||
match scope.search(var_name) {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
return match self.global_modules.iter().find_map(|m| m.get_var(var_name)) {
|
||||
Some(val) => Ok(val.into()),
|
||||
None => Err(ERR::ErrorVariableNotFound(
|
||||
var_name.to_string(),
|
||||
expr.position(),
|
||||
return self
|
||||
.global_modules
|
||||
.iter()
|
||||
.find_map(|m| m.get_var(var_name))
|
||||
.map_or_else(
|
||||
|| {
|
||||
Err(ERR::ErrorVariableNotFound(
|
||||
var_name.to_string(),
|
||||
expr.position(),
|
||||
)
|
||||
.into())
|
||||
},
|
||||
|val| Ok(val.into()),
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -533,6 +533,7 @@ impl Engine {
|
||||
let index_value = x as INT;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
#[allow(clippy::absurd_extreme_comparisons)]
|
||||
if index_value > crate::MAX_USIZE_INT {
|
||||
return Err(ERR::ErrorArithmetic(
|
||||
format!("for-loop counter overflow: {x}"),
|
||||
@@ -799,10 +800,10 @@ impl Engine {
|
||||
Err(ERR::ErrorModuleNotFound(path.to_string(), path_pos).into())
|
||||
})?;
|
||||
|
||||
let (export, must_be_indexed) = if !export.is_empty() {
|
||||
(export.name.clone(), true)
|
||||
} else {
|
||||
let (export, must_be_indexed) = if export.is_empty() {
|
||||
(self.const_empty_string(), false)
|
||||
} else {
|
||||
(export.name.clone(), true)
|
||||
};
|
||||
|
||||
if !must_be_indexed || module.is_indexed() {
|
||||
@@ -824,13 +825,14 @@ impl Engine {
|
||||
Stmt::Export(x, ..) => {
|
||||
let (Ident { name, pos, .. }, Ident { name: alias, .. }) = &**x;
|
||||
// Mark scope variables as public
|
||||
if let Some(index) = scope.search(name) {
|
||||
let alias = if alias.is_empty() { name } else { alias }.clone();
|
||||
scope.add_alias_by_index(index, alias.into());
|
||||
Ok(Dynamic::UNIT)
|
||||
} else {
|
||||
Err(ERR::ErrorVariableNotFound(name.to_string(), *pos).into())
|
||||
}
|
||||
scope.search(name).map_or_else(
|
||||
|| Err(ERR::ErrorVariableNotFound(name.to_string(), *pos).into()),
|
||||
|index| {
|
||||
let alias = if alias.is_empty() { name } else { alias }.clone();
|
||||
scope.add_alias_by_index(index, alias);
|
||||
Ok(Dynamic::UNIT)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Share statement
|
||||
@@ -838,20 +840,21 @@ impl Engine {
|
||||
Stmt::Share(x) => {
|
||||
x.iter()
|
||||
.try_for_each(|(name, index, pos)| {
|
||||
if let Some(index) = index
|
||||
index
|
||||
.map(|n| scope.len() - n.get())
|
||||
.or_else(|| scope.search(name))
|
||||
{
|
||||
let val = scope.get_mut_by_index(index);
|
||||
.map_or_else(
|
||||
|| Err(ERR::ErrorVariableNotFound(name.to_string(), *pos).into()),
|
||||
|index| {
|
||||
let val = scope.get_mut_by_index(index);
|
||||
|
||||
if !val.is_shared() {
|
||||
// Replace the variable with a shared value.
|
||||
*val = std::mem::take(val).into_shared();
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ERR::ErrorVariableNotFound(name.to_string(), *pos).into())
|
||||
}
|
||||
if !val.is_shared() {
|
||||
// Replace the variable with a shared value.
|
||||
*val = std::mem::take(val).into_shared();
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
})
|
||||
.map(|_| Dynamic::UNIT)
|
||||
}
|
||||
|
@@ -15,6 +15,11 @@ use std::{
|
||||
/// Values going over bounds are limited to the actual length.
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
#[inline]
|
||||
#[allow(
|
||||
clippy::cast_sign_loss,
|
||||
clippy::absurd_extreme_comparisons,
|
||||
clippy::cast_possible_truncation
|
||||
)]
|
||||
pub fn calc_offset_len(length: usize, start: crate::INT, len: crate::INT) -> (usize, usize) {
|
||||
let start = if start < 0 {
|
||||
let abs_start = start.unsigned_abs();
|
||||
@@ -47,6 +52,11 @@ pub fn calc_offset_len(length: usize, start: crate::INT, len: crate::INT) -> (us
|
||||
/// Values going over bounds call the provided closure to return a default value or an error.
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
#[allow(
|
||||
clippy::cast_sign_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::absurd_extreme_comparisons
|
||||
)]
|
||||
pub fn calc_index<E>(
|
||||
length: usize,
|
||||
start: crate::INT,
|
||||
@@ -54,13 +64,14 @@ pub fn calc_index<E>(
|
||||
err_func: impl FnOnce() -> Result<usize, E>,
|
||||
) -> Result<usize, E> {
|
||||
if start < 0 && negative_count_from_end {
|
||||
let abs_start = start.unsigned_abs() as usize;
|
||||
|
||||
// Count from end if negative
|
||||
if abs_start <= length {
|
||||
return Ok(length - abs_start);
|
||||
}
|
||||
let abs_start = start.unsigned_abs();
|
||||
return Ok(if abs_start as u64 > crate::MAX_USIZE_INT as u64 {
|
||||
0
|
||||
} else {
|
||||
length - usize::min(abs_start as usize, length)
|
||||
});
|
||||
}
|
||||
|
||||
if start <= crate::MAX_USIZE_INT && (start as usize) < length {
|
||||
return Ok(start as usize);
|
||||
}
|
||||
@@ -313,7 +324,10 @@ impl<'a> Target<'a> {
|
||||
|
||||
let value = &mut *source.write_lock::<crate::Blob>().expect("`Blob`");
|
||||
|
||||
value[*index] = (new_byte & 0x00ff) as u8;
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
{
|
||||
value[*index] = (new_byte & 0x00ff) as u8;
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Self::StringChar {
|
||||
|
Reference in New Issue
Block a user