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(") -> ");
sig.push_str(&return_type); sig.push_str(&return_type);
} else { } else {
sig.push_str(")"); sig.push(')');
} }
} else { } else {
for x in 0..self.params { for x in 0..self.params {
sig.push_str("_"); sig.push('_');
if x < self.params - 1 { if x < self.params - 1 {
sig.push_str(", "); sig.push_str(", ");
} }
} }
if self.func.is_script() { if self.func.is_script() {
sig.push_str(")"); sig.push(')');
} else { } else {
sig.push_str(") -> ?"); sig.push_str(") -> ?");
} }
@ -366,7 +366,6 @@ impl Module {
/// Exported under the `metadata` feature only. /// Exported under the `metadata` feature only.
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
#[inline(always)] #[inline(always)]
#[must_use]
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ { pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
self.functions self.functions
.values() .values()
@ -630,9 +629,9 @@ impl Module {
.map(|&name| self.identifiers.get(name)) .map(|&name| self.identifiers.get(name))
.collect(); .collect();
self.functions if let Some(f) = self.functions.get_mut(&hash_fn) {
.get_mut(&hash_fn) f.param_names = param_names;
.map(|f| f.param_names = param_names); }
self 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")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
use std::{collections::BTreeMap, ops::AddAssign}; 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>)> { pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
self.0.iter_mut().map(|(k, v)| (k.as_str(), v)) 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. /// Get an iterator of all the [module][Module] paths.
#[inline(always)] #[inline(always)]
pub fn paths(&self) -> impl Iterator<Item = &str> { 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 { impl ModuleResolver for StaticModuleResolver {
#[inline(always)] #[inline(always)]
fn resolve( fn resolve(

View File

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

View File

@ -33,12 +33,10 @@ impl<'de> DynamicDeserializer<'de> {
Self { value } Self { value }
} }
/// Shortcut for a type conversion error. /// Shortcut for a type conversion error.
#[must_use]
fn type_error<T>(&self) -> Result<T, Box<EvalAltResult>> { fn type_error<T>(&self) -> Result<T, Box<EvalAltResult>> {
self.type_error_str(type_name::<T>()) self.type_error_str(type_name::<T>())
} }
/// Shortcut for a type conversion error. /// Shortcut for a type conversion error.
#[must_use]
fn type_error_str<T>(&self, error: &str) -> Result<T, Box<EvalAltResult>> { fn type_error_str<T>(&self, error: &str) -> Result<T, Box<EvalAltResult>> {
EvalAltResult::ErrorMismatchOutputType( EvalAltResult::ErrorMismatchOutputType(
error.into(), error.into(),
@ -47,7 +45,6 @@ impl<'de> DynamicDeserializer<'de> {
) )
.into() .into()
} }
#[must_use]
fn deserialize_int<V: Visitor<'de>>( fn deserialize_int<V: Visitor<'de>>(
&mut self, &mut self,
v: crate::INT, v: crate::INT,
@ -111,7 +108,6 @@ impl<'de> DynamicDeserializer<'de> {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[must_use]
pub fn from_dynamic<'de, T: Deserialize<'de>>( pub fn from_dynamic<'de, T: Deserialize<'de>>(
value: &'de Dynamic, value: &'de Dynamic,
) -> Result<T, Box<EvalAltResult>> { ) -> 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> { fn visit_i64<E: Error>(self, v: i64) -> Result<Self::Value, E> {
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
return Ok(v.into()); {
Ok(v.into())
}
#[cfg(feature = "only_i32")] #[cfg(feature = "only_i32")]
if v > i32::MAX as i64 { if v > i32::MAX as i64 {
return Ok(Dynamic::from(v)); Ok(Dynamic::from(v))
} else { } 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> { 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> { fn visit_u32<E: Error>(self, v: u32) -> Result<Self::Value, E> {
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
return Ok(INT::from(v).into()); {
Ok(INT::from(v).into())
}
#[cfg(feature = "only_i32")] #[cfg(feature = "only_i32")]
if v > i32::MAX as u32 { if v > i32::MAX as u32 {
return Ok(Dynamic::from(v)); Ok(Dynamic::from(v))
} else { } 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> { fn visit_u64<E: Error>(self, v: u64) -> Result<Self::Value, E> {
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
if v > i64::MAX as u64 { if v > i64::MAX as u64 {
return Ok(Dynamic::from(v)); Ok(Dynamic::from(v))
} else { } else {
return self.visit_i64(v as i64); self.visit_i64(v as i64)
} }
#[cfg(feature = "only_i32")] #[cfg(feature = "only_i32")]
if v > i32::MAX as u64 { if v > i32::MAX as u64 {
return Ok(Dynamic::from(v)); Ok(Dynamic::from(v))
} else { } 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")] #[serde(rename_all = "camelCase")]
struct FnParam { struct FnParam {
pub name: String, 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)] #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct FnMetadata { struct FnMetadata {
@ -128,7 +137,7 @@ impl From<&crate::module::FuncInfo> for FnMetadata {
let name = seg let name = seg
.next() .next()
.map(|s| s.trim().to_string()) .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()); let typ = seg.next().map(|s| s.trim().to_string());
FnParam { name, typ } FnParam { name, typ }
}) })
@ -218,7 +227,6 @@ impl Engine {
/// 2) Functions registered into the global namespace /// 2) Functions registered into the global namespace
/// 3) Functions in static modules /// 3) Functions in static modules
/// 4) Functions in global modules (optional) /// 4) Functions in global modules (optional)
#[must_use]
pub fn gen_fn_metadata_with_ast_to_json( pub fn gen_fn_metadata_with_ast_to_json(
&self, &self,
ast: &AST, ast: &AST,
@ -258,7 +266,6 @@ impl Engine {
/// 1) Functions registered into the global namespace /// 1) Functions registered into the global namespace
/// 2) Functions in static modules /// 2) Functions in static modules
/// 3) Functions in global modules (optional) /// 3) Functions in global modules (optional)
#[must_use]
pub fn gen_fn_metadata_to_json(&self, include_global: bool) -> serde_json::Result<String> { 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) self.gen_fn_metadata_with_ast_to_json(&Default::default(), include_global)
} }

View File

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

View File

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