Skip to content

Commit

Permalink
chore: make clippy happy (#388)
Browse files Browse the repository at this point in the history
Co-authored-by: hzlinyiyu <[email protected]>
  • Loading branch information
attila-lin and hzlinyiyu-netease authored Mar 25, 2024
1 parent 6e6c73e commit b62f2ee
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 22 deletions.
1 change: 0 additions & 1 deletion mlua-sys/src/lua51/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! Based on github.com/keplerproject/lua-compat-5.3

use std::convert::TryInto;
use std::mem;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
Expand Down
1 change: 0 additions & 1 deletion mlua-sys/src/lua52/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! Based on github.com/keplerproject/lua-compat-5.3

use std::convert::TryInto;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;

Expand Down
1 change: 0 additions & 1 deletion mlua_derive/src/token.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
cmp::{Eq, PartialEq},
fmt::{self, Display, Formatter},
iter::IntoIterator,
vec::IntoIter,
};

Expand Down
16 changes: 10 additions & 6 deletions src/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::convert::TryInto;
use std::ffi::{CStr, CString};
use std::hash::{BuildHasher, Hash};
use std::os::raw::c_int;
Expand Down Expand Up @@ -67,7 +66,8 @@ impl<'lua> IntoLua<'lua> for &String<'lua> {

#[inline]
unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> {
Ok(lua.push_ref(&self.0))
lua.push_ref(&self.0);
Ok(())
}
}

Expand Down Expand Up @@ -131,7 +131,8 @@ impl<'lua> IntoLua<'lua> for &Table<'lua> {

#[inline]
unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> {
Ok(lua.push_ref(&self.0))
lua.push_ref(&self.0);
Ok(())
}
}

Expand Down Expand Up @@ -196,7 +197,8 @@ impl<'lua> IntoLua<'lua> for &Function<'lua> {

#[inline]
unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> {
Ok(lua.push_ref(&self.0))
lua.push_ref(&self.0);
Ok(())
}
}

Expand Down Expand Up @@ -261,7 +263,8 @@ impl<'lua> IntoLua<'lua> for &Thread<'lua> {

#[inline]
unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> {
Ok(lua.push_ref(&self.0))
lua.push_ref(&self.0);
Ok(())
}
}

Expand Down Expand Up @@ -326,7 +329,8 @@ impl<'lua> IntoLua<'lua> for &AnyUserData<'lua> {

#[inline]
unsafe fn push_into_stack(self, lua: &'lua Lua) -> Result<()> {
Ok(lua.push_ref(&self.0))
lua.push_ref(&self.0);
Ok(())
}
}

Expand Down
1 change: 1 addition & 0 deletions src/luau/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub(crate) fn register_package_module(lua: &Lua) -> Result<()> {
Ok(())
}

#[allow(unused_variables)]
pub(crate) fn disable_dylibs(lua: &Lua) {
// Presence of `LoadedDylibs` in app data is used as a flag
// to check whether binary modules are enabled
Expand Down
1 change: 0 additions & 1 deletion src/multi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::iter::FromIterator;
use std::ops::{Deref, DerefMut};
use std::os::raw::c_int;
use std::result::Result as StdResult;
Expand Down
5 changes: 1 addition & 4 deletions src/serde/de.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cell::RefCell;
use std::convert::TryInto;
use std::os::raw::c_void;
use std::rc::Rc;
use std::result::Result as StdResult;
Expand Down Expand Up @@ -134,9 +133,7 @@ impl<'lua, 'de> serde::Deserializer<'de> for Deserializer<'lua> {
Value::Nil => visitor.visit_unit(),
Value::Boolean(b) => visitor.visit_bool(b),
#[allow(clippy::useless_conversion)]
Value::Integer(i) => {
visitor.visit_i64(i.try_into().expect("cannot convert lua_Integer to i64"))
}
Value::Integer(i) => visitor.visit_i64(i.into()),
#[allow(clippy::useless_conversion)]
Value::Number(n) => visitor.visit_f64(n.into()),
#[cfg(feature = "luau")]
Expand Down
4 changes: 2 additions & 2 deletions src/serde/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<'lua> ser::SerializeStruct for SerializeStruct<'lua> {
Some(table @ Value::Table(_)) => Ok(table),
Some(value) if self.options.detect_serde_json_arbitrary_precision => {
let number_s = value.as_str().expect("not an arbitrary precision number");
if number_s.contains(&['.', 'e', 'E']) {
if number_s.contains(['.', 'e', 'E']) {
if let Ok(number) = number_s.parse().map(Value::Number) {
return Ok(number);
}
Expand All @@ -544,7 +544,7 @@ impl<'lua> ser::SerializeStruct for SerializeStruct<'lua> {
.parse()
.map(Value::Integer)
.or_else(|_| number_s.parse().map(Value::Number))
.unwrap_or_else(|_| value))
.unwrap_or(value))
}
_ => unreachable!(),
}
Expand Down
10 changes: 4 additions & 6 deletions src/value.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::cmp::Ordering;
use std::collections::HashSet;
use std::iter::{self, FromIterator};
use std::iter;
use std::ops::Index;
use std::os::raw::{c_int, c_void};
use std::string::String as StdString;
Expand All @@ -15,7 +15,7 @@ use {
crate::table::SerializableTable,
rustc_hash::FxHashSet,
serde::ser::{self, Serialize, Serializer},
std::{cell::RefCell, convert::TryInto, rc::Rc, result::Result as StdResult},
std::{cell::RefCell, rc::Rc, result::Result as StdResult},
};

use crate::error::{Error, Result};
Expand Down Expand Up @@ -252,8 +252,7 @@ impl<'lua> Value<'lua> {
/// If the value is a Lua [`Integer`], try to convert it to `i64` or return `None` otherwise.
#[inline]
pub fn as_i64(&self) -> Option<i64> {
#[allow(clippy::useless_conversion)]
self.as_integer().and_then(|i| i64::try_from(i).ok())
self.as_integer().map(i64::from)
}

/// Cast the value to `u64`.
Expand Down Expand Up @@ -659,8 +658,7 @@ impl<'a, 'lua> Serialize for SerializableValue<'a, 'lua> {
Value::Nil => serializer.serialize_unit(),
Value::Boolean(b) => serializer.serialize_bool(*b),
#[allow(clippy::useless_conversion)]
Value::Integer(i) => serializer
.serialize_i64((*i).try_into().expect("cannot convert Lua Integer to i64")),
Value::Integer(i) => serializer.serialize_i64((*i).into()),
Value::Number(n) => serializer.serialize_f64(*n),
#[cfg(feature = "luau")]
Value::Vector(v) => v.serialize(serializer),
Expand Down

0 comments on commit b62f2ee

Please sign in to comment.