Clean up more clippy.

This commit is contained in:
Stephen Chung
2022-07-27 18:04:59 +08:00
parent 39dee556c4
commit 2f948a784c
47 changed files with 412 additions and 377 deletions

View File

@@ -554,19 +554,19 @@ impl AST {
lib
};
let mut _ast = if !other.source.is_empty() {
let mut _ast = if other.source.is_empty() {
Self::new(
merged,
#[cfg(not(feature = "no_function"))]
lib,
)
} else {
Self::new_with_source(
merged,
#[cfg(not(feature = "no_function"))]
lib,
other.source.clone(),
)
} else {
Self::new(
merged,
#[cfg(not(feature = "no_function"))]
lib,
)
};
#[cfg(not(feature = "no_module"))]
@@ -977,6 +977,7 @@ impl Eq for ASTNode<'_> {}
impl ASTNode<'_> {
/// Get the [`Position`] of this [`ASTNode`].
#[must_use]
pub fn position(&self) -> Position {
match self {
ASTNode::Stmt(stmt) => stmt.position(),

View File

@@ -326,10 +326,10 @@ impl<F: Float + FromStr> FromStr for FloatWrapper<F> {
#[cfg(not(feature = "no_float"))]
impl<F: Float> FloatWrapper<F> {
/// Maximum floating-point number for natural display before switching to scientific notation.
pub const MAX_NATURAL_FLOAT_FOR_DISPLAY: f32 = 10000000000000.0;
pub const MAX_NATURAL_FLOAT_FOR_DISPLAY: f32 = 10_000_000_000_000.0;
/// Minimum floating-point number for natural display before switching to scientific notation.
pub const MIN_NATURAL_FLOAT_FOR_DISPLAY: f32 = 0.0000000000001;
pub const MIN_NATURAL_FLOAT_FOR_DISPLAY: f32 = 0.000_000_000_000_1;
/// Create a new [`FloatWrapper`].
#[inline(always)]
@@ -728,10 +728,10 @@ impl Expr {
match self {
#[cfg(not(feature = "no_module"))]
Self::Variable(x, ..) => {
if !x.1.is_empty() {
x.1.position()
} else {
if x.1.is_empty() {
self.position()
} else {
x.1.position()
}
}

View File

@@ -58,6 +58,7 @@ impl Ident {
/// Get the name of the identifier as a string slice.
#[inline(always)]
#[must_use]
pub fn as_str(&self) -> &str {
self.name.as_str()
}

View File

@@ -42,7 +42,7 @@ impl fmt::Debug for Namespace {
&self
.path
.iter()
.map(|m| m.as_str())
.map(Ident::as_str)
.collect::<StaticVec<_>>()
.join(Token::DoubleColon.literal_syntax()),
)
@@ -59,7 +59,7 @@ impl fmt::Display for Namespace {
&self
.path
.iter()
.map(|m| m.as_str())
.map(Ident::as_str)
.collect::<StaticVec<_>>()
.join(Token::DoubleColon.literal_syntax()),
)
@@ -126,7 +126,7 @@ impl Namespace {
/// Set the [`Scope`][crate::Scope] index offset.
#[inline(always)]
pub(crate) fn set_index(&mut self, index: Option<NonZeroUsize>) {
self.index = index
self.index = index;
}
/// Get the [position][Position] of this [`Namespace`].
///

View File

@@ -2,7 +2,7 @@
#![cfg(not(feature = "no_function"))]
use super::{FnAccess, StmtBlock};
use crate::{Identifier, StaticVec};
use crate::{Identifier, SmartString, StaticVec};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{fmt, hash::Hash};
@@ -71,7 +71,7 @@ impl fmt::Display for ScriptFnDef {
self.name,
self.params
.iter()
.map(|s| s.as_str())
.map(SmartString::as_str)
.collect::<StaticVec<_>>()
.join(", ")
)
@@ -120,7 +120,7 @@ impl fmt::Display for ScriptFnMetadata<'_> {
self.name,
self.params
.iter()
.cloned()
.copied()
.collect::<StaticVec<_>>()
.join(", ")
)
@@ -132,7 +132,7 @@ impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> {
fn from(value: &'a ScriptFnDef) -> Self {
Self {
name: &value.name,
params: value.params.iter().map(|s| s.as_str()).collect(),
params: value.params.iter().map(SmartString::as_str).collect(),
access: value.access,
#[cfg(feature = "metadata")]
comments: value.comments.iter().map(<_>::as_ref).collect(),

View File

@@ -507,7 +507,7 @@ impl<'a> IntoIterator for &'a StmtBlock {
impl Extend<Stmt> for StmtBlock {
#[inline(always)]
fn extend<T: IntoIterator<Item = Stmt>>(&mut self, iter: T) {
self.block.extend(iter)
self.block.extend(iter);
}
}
@@ -799,7 +799,7 @@ impl Stmt {
Self::For(x, ..) => x.2.is_pure() && x.3.iter().all(Stmt::is_pure),
Self::Var(..) | Self::Assignment(..) | Self::FnCall(..) => false,
Self::Block(block, ..) => block.iter().all(|stmt| stmt.is_pure()),
Self::Block(block, ..) => block.iter().all(Stmt::is_pure),
Self::BreakLoop(..) | Self::Return(..) => false,
Self::TryCatch(x, ..) => {
x.try_block.iter().all(Stmt::is_pure) && x.catch_block.iter().all(Stmt::is_pure)