Satisfy clippy.

This commit is contained in:
Stephen Chung 2021-07-26 22:22:27 +08:00
parent 2c50738c6c
commit 29133cf973
9 changed files with 75 additions and 63 deletions

View File

@ -81,18 +81,18 @@ impl FuncInfo {
sig.push_str(") -> ");
sig.push_str(&return_type);
} else {
sig.push_str(")");
sig.push(')');
}
} else {
for x in 0..self.params {
sig.push_str("_");
sig.push('_');
if x < self.params - 1 {
sig.push_str(", ");
}
}
if self.func.is_script() {
sig.push_str(")");
sig.push(')');
} else {
sig.push_str(") -> ?");
}
@ -366,7 +366,6 @@ impl Module {
/// Exported under the `metadata` feature only.
#[cfg(feature = "metadata")]
#[inline(always)]
#[must_use]
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
self.functions
.values()
@ -630,9 +629,9 @@ impl Module {
.map(|&name| self.identifiers.get(name))
.collect();
self.functions
.get_mut(&hash_fn)
.map(|f| f.param_names = param_names);
if let Some(f) = self.functions.get_mut(&hash_fn) {
f.param_names = param_names;
}
self
}

View File

@ -1,4 +1,6 @@
use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Shared};
use crate::{
Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Shared, SmartString,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{collections::BTreeMap, ops::AddAssign};
@ -72,11 +74,6 @@ impl StaticModuleResolver {
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
}
/// Get a mutable iterator of all the modules.
#[inline(always)]
pub fn into_iter(self) -> impl Iterator<Item = (Identifier, Shared<Module>)> {
self.0.into_iter()
}
/// Get an iterator of all the [module][Module] paths.
#[inline(always)]
pub fn paths(&self) -> impl Iterator<Item = &str> {
@ -117,6 +114,15 @@ impl StaticModuleResolver {
}
}
impl IntoIterator for StaticModuleResolver {
type Item = (Identifier, Shared<Module>);
type IntoIter = std::collections::btree_map::IntoIter<SmartString, Shared<Module>>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl ModuleResolver for StaticModuleResolver {
#[inline(always)]
fn resolve(

View File

@ -2115,14 +2115,12 @@ fn parse_expr(
match token {
Token::Custom(key) | Token::Reserved(key) | Token::Identifier(key) => {
match state.engine.custom_syntax.get_key_value(key.as_str()) {
Some((key, syntax)) => {
input.next().expect(NEVER_ENDS);
return parse_custom_syntax(
input, state, lib, settings, key, syntax, token_pos,
);
}
_ => (),
if let Some((key, syntax)) = state.engine.custom_syntax.get_key_value(key.as_str())
{
input.next().expect(NEVER_ENDS);
return parse_custom_syntax(
input, state, lib, settings, key, syntax, token_pos,
);
}
}
_ => (),

View File

@ -33,12 +33,10 @@ impl<'de> DynamicDeserializer<'de> {
Self { value }
}
/// Shortcut for a type conversion error.
#[must_use]
fn type_error<T>(&self) -> Result<T, Box<EvalAltResult>> {
self.type_error_str(type_name::<T>())
}
/// Shortcut for a type conversion error.
#[must_use]
fn type_error_str<T>(&self, error: &str) -> Result<T, Box<EvalAltResult>> {
EvalAltResult::ErrorMismatchOutputType(
error.into(),
@ -47,7 +45,6 @@ impl<'de> DynamicDeserializer<'de> {
)
.into()
}
#[must_use]
fn deserialize_int<V: Visitor<'de>>(
&mut self,
v: crate::INT,
@ -111,7 +108,6 @@ impl<'de> DynamicDeserializer<'de> {
/// # Ok(())
/// # }
/// ```
#[must_use]
pub fn from_dynamic<'de, T: Deserialize<'de>>(
value: &'de Dynamic,
) -> Result<T, Box<EvalAltResult>> {

View File

@ -40,12 +40,14 @@ impl<'d> Visitor<'d> for DynamicVisitor {
}
fn visit_i64<E: Error>(self, v: i64) -> Result<Self::Value, E> {
#[cfg(not(feature = "only_i32"))]
return Ok(v.into());
{
Ok(v.into())
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as i64 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.visit_i32(v as i32);
self.visit_i32(v as i32)
}
}
fn visit_u8<E: Error>(self, v: u8) -> Result<Self::Value, E> {
@ -56,26 +58,28 @@ impl<'d> Visitor<'d> for DynamicVisitor {
}
fn visit_u32<E: Error>(self, v: u32) -> Result<Self::Value, E> {
#[cfg(not(feature = "only_i32"))]
return Ok(INT::from(v).into());
{
Ok(INT::from(v).into())
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as u32 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.visit_i32(v as i32);
self.visit_i32(v as i32)
}
}
fn visit_u64<E: Error>(self, v: u64) -> Result<Self::Value, E> {
#[cfg(not(feature = "only_i32"))]
if v > i64::MAX as u64 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.visit_i64(v as i64);
self.visit_i64(v as i64)
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as u64 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.visit_i32(v as i32);
self.visit_i32(v as i32)
}
}

View File

@ -43,7 +43,7 @@ impl From<crate::FnAccess> for FnAccess {
}
}
#[derive(Debug, Clone, Eq, PartialEq, Ord, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FnParam {
pub name: String,
@ -71,6 +71,15 @@ impl PartialOrd for FnParam {
}
}
impl Ord for FnParam {
fn cmp(&self, other: &Self) -> Ordering {
match self.name.cmp(&other.name) {
Ordering::Equal => self.typ.cmp(&other.typ),
cmp => cmp,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FnMetadata {
@ -128,7 +137,7 @@ impl From<&crate::module::FuncInfo> for FnMetadata {
let name = seg
.next()
.map(|s| s.trim().to_string())
.unwrap_or("_".to_string());
.unwrap_or_else(|| "_".to_string());
let typ = seg.next().map(|s| s.trim().to_string());
FnParam { name, typ }
})
@ -218,7 +227,6 @@ impl Engine {
/// 2) Functions registered into the global namespace
/// 3) Functions in static modules
/// 4) Functions in global modules (optional)
#[must_use]
pub fn gen_fn_metadata_with_ast_to_json(
&self,
ast: &AST,
@ -258,7 +266,6 @@ impl Engine {
/// 1) Functions registered into the global namespace
/// 2) Functions in static modules
/// 3) Functions in global modules (optional)
#[must_use]
pub fn gen_fn_metadata_to_json(&self, include_global: bool) -> serde_json::Result<String> {
self.gen_fn_metadata_with_ast_to_json(&Default::default(), include_global)
}

View File

@ -82,7 +82,6 @@ impl DynamicSerializer {
/// # Ok(())
/// # }
/// ```
#[must_use]
pub fn to_dynamic<T: Serialize>(value: T) -> RhaiResult {
let mut s = DynamicSerializer::new(Default::default());
value.serialize(&mut s)
@ -138,27 +137,29 @@ impl Serializer for &mut DynamicSerializer {
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Box<EvalAltResult>> {
#[cfg(not(feature = "only_i32"))]
return Ok(v.into());
{
Ok(v.into())
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as i64 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i32(v as i32);
self.serialize_i32(v as i32)
}
}
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Box<EvalAltResult>> {
#[cfg(not(feature = "only_i32"))]
if v > i64::MAX as i128 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i64(v as i64);
self.serialize_i64(v as i64)
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as i128 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i32(v as i32);
self.serialize_i32(v as i32)
}
}
@ -178,42 +179,44 @@ impl Serializer for &mut DynamicSerializer {
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Box<EvalAltResult>> {
#[cfg(not(feature = "only_i32"))]
return self.serialize_i64(i64::from(v));
{
self.serialize_i64(i64::from(v))
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as u32 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i32(v as i32);
self.serialize_i32(v as i32)
}
}
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Box<EvalAltResult>> {
#[cfg(not(feature = "only_i32"))]
if v > i64::MAX as u64 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i64(v as i64);
self.serialize_i64(v as i64)
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as u64 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i32(v as i32);
self.serialize_i32(v as i32)
}
}
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Box<EvalAltResult>> {
#[cfg(not(feature = "only_i32"))]
if v > i64::MAX as u128 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i64(v as i64);
self.serialize_i64(v as i64)
}
#[cfg(feature = "only_i32")]
if v > i32::MAX as u128 {
return Ok(Dynamic::from(v));
Ok(Dynamic::from(v))
} else {
return self.serialize_i32(v as i32);
self.serialize_i32(v as i32)
}
}

View File

@ -18,7 +18,6 @@ impl<'a> StringSliceDeserializer<'a> {
Self { value }
}
/// Shortcut for a type conversion error.
#[must_use]
fn type_error<T>(&self) -> Result<T, Box<EvalAltResult>> {
EvalAltResult::ErrorMismatchOutputType(
type_name::<T>().into(),

View File

@ -1281,22 +1281,22 @@ fn scan_block_comment(
match c {
'/' => {
stream.peek_next().filter(|&c2| c2 == '*').map(|c2| {
if let Some(c2) = stream.peek_next().filter(|&c2| c2 == '*') {
eat_next(stream, pos);
if let Some(comment) = comment.as_mut() {
comment.push(c2);
}
level += 1;
});
}
}
'*' => {
stream.peek_next().filter(|&c2| c2 == '/').map(|c2| {
if let Some(c2) = stream.peek_next().filter(|&c2| c2 == '/') {
eat_next(stream, pos);
if let Some(comment) = comment.as_mut() {
comment.push(c2);
}
level -= 1;
});
}
}
'\n' => pos.new_line(),
_ => (),