summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2022-03-22 00:18:42 +0000
committerAlex Orlenko <zxteam@protonmail.com>2022-03-22 00:47:31 +0000
commit55b778c68bf98ca82a779a4cf792fabc8fb15d69 (patch)
tree76237a1b251ba5487faacb62934f286d209b9ee3
parentc6d37271711d3993b6269a6db956d3951515b761 (diff)
downloadmlua-55b778c68bf98ca82a779a4cf792fabc8fb15d69.zip
Fix clippy warnings
-rw-r--r--build/find_normal.rs2
-rw-r--r--src/ffi/lua51/compat.rs4
-rw-r--r--src/ffi/luau/compat.rs25
-rw-r--r--src/lua.rs12
-rw-r--r--src/scope.rs6
5 files changed, 21 insertions, 28 deletions
diff --git a/build/find_normal.rs b/build/find_normal.rs
index d9c0e1c..d5b8074 100644
--- a/build/find_normal.rs
+++ b/build/find_normal.rs
@@ -70,7 +70,7 @@ pub fn probe_lua() -> Option<PathBuf> {
.probe(alt_probe);
}
- lua.expect(&format!("cannot find Lua {} using `pkg-config`", ver))
+ lua.unwrap_or_else(|_| panic!("cannot find Lua {} using `pkg-config`", ver))
.include_paths
.get(0)
.cloned()
diff --git a/src/ffi/lua51/compat.rs b/src/ffi/lua51/compat.rs
index ca0379b..892c507 100644
--- a/src/ffi/lua51/compat.rs
+++ b/src/ffi/lua51/compat.rs
@@ -110,10 +110,10 @@ unsafe fn compat53_pushglobalfuncname(L: *mut lua_State, ar: *mut lua_Debug) ->
if compat53_findfield(L, top + 1, 2) != 0 {
lua_copy(L, -1, top + 1); // move name to proper place
lua_pop(L, 2); // remove pushed values
- return 1;
+ 1
} else {
lua_settop(L, top); // remove function and global table
- return 0;
+ 0
}
}
diff --git a/src/ffi/luau/compat.rs b/src/ffi/luau/compat.rs
index 26d3fd8..f92e858 100644
--- a/src/ffi/luau/compat.rs
+++ b/src/ffi/luau/compat.rs
@@ -2,7 +2,6 @@
//!
//! Based on github.com/keplerproject/lua-compat-5.3
-use std::convert::TryInto;
use std::ffi::CStr;
use std::mem;
use std::os::raw::{c_char, c_int, c_void};
@@ -51,7 +50,7 @@ unsafe fn compat53_findfield(L: *mut lua_State, objidx: c_int, level: c_int) ->
}
lua_pop(L, 1); // remove value
}
- return 0; // not found
+ 0 // not found
}
unsafe fn compat53_pushglobalfuncname(
@@ -66,10 +65,10 @@ unsafe fn compat53_pushglobalfuncname(
if compat53_findfield(L, top + 1, 2) != 0 {
lua_copy(L, -1, top + 1); // move name to proper place
lua_pop(L, 2); // remove pushed values
- return 1;
+ 1
} else {
lua_settop(L, top); // remove function and global table
- return 0;
+ 0
}
}
@@ -77,13 +76,11 @@ unsafe fn compat53_pushfuncname(L: *mut lua_State, level: c_int, ar: *mut lua_De
if !(*ar).name.is_null() {
// is there a name?
lua_pushfstring(L, cstr!("function '%s'"), (*ar).name);
+ } else if compat53_pushglobalfuncname(L, level, ar) != 0 {
+ lua_pushfstring(L, cstr!("function '%s'"), lua_tostring(L, -1));
+ lua_remove(L, -2); // remove name
} else {
- if compat53_pushglobalfuncname(L, level, ar) != 0 {
- lua_pushfstring(L, cstr!("function '%s'"), lua_tostring(L, -1));
- lua_remove(L, -2); // remove name
- } else {
- lua_pushliteral(L, "?");
- }
+ lua_pushliteral(L, "?");
}
}
@@ -177,7 +174,6 @@ pub unsafe fn lua_geti(L: *mut lua_State, mut idx: c_int, n: lua_Integer) -> c_i
#[inline(always)]
pub unsafe fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int {
- let n = n.try_into().expect("cannot convert index to lua_Integer");
lua_rawgeti_(L, idx, n)
}
@@ -213,7 +209,6 @@ pub unsafe fn lua_seti(L: *mut lua_State, mut idx: c_int, n: lua_Integer) {
#[inline(always)]
pub unsafe fn lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer) {
- let n = n.try_into().expect("cannot convert index from lua_Integer");
lua_rawseti_(L, idx, n)
}
@@ -366,10 +361,8 @@ pub unsafe fn luaL_loadbufferx(
if !ok {
return LUA_ERRSYNTAX;
}
- } else {
- if luau_load(L, name, data, size, 0) != 0 {
- return LUA_ERRSYNTAX;
- }
+ } else if luau_load(L, name, data, size, 0) != 0 {
+ return LUA_ERRSYNTAX;
}
LUA_OK
}
diff --git a/src/lua.rs b/src/lua.rs
index c0782ef..920801f 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -1351,7 +1351,7 @@ impl Lua {
{
let func = RefCell::new(func);
self.create_function(move |lua, args| {
- (&mut *func
+ (*func
.try_borrow_mut()
.map_err(|_| Error::RecursiveMutCallback)?)(lua, args)
})
@@ -2613,12 +2613,12 @@ impl Lua {
match option.to_str() {
Ok("collect") => {
ffi::lua_gc(state, ffi::LUA_GCCOLLECT, 0);
- return 0;
+ 0
}
Ok("count") => {
let n = ffi::lua_gc(state, ffi::LUA_GCCOUNT, 0);
ffi::lua_pushnumber(state, n as ffi::lua_Number);
- return 1;
+ 1
}
// TODO: More variants
_ => ffi::luaL_error(
@@ -2629,7 +2629,7 @@ impl Lua {
}
fn lua_require(lua: &Lua, name: Option<std::string::String>) -> Result<Value> {
- let name = name.ok_or(Error::RuntimeError("name is nil".into()))?;
+ let name = name.ok_or_else(|| Error::RuntimeError("name is nil".into()))?;
// Find module in the cache
let loaded = unsafe {
@@ -2651,8 +2651,8 @@ impl Lua {
}
let mut source = None;
- for path in search_path.split(";") {
- if let Ok(buf) = std::fs::read(path.replacen("?", &name, 1)) {
+ for path in search_path.split(';') {
+ if let Ok(buf) = std::fs::read(path.replacen('?', &name, 1)) {
source = Some(buf);
break;
}
diff --git a/src/scope.rs b/src/scope.rs
index 2a3c710..8fd9d90 100644
--- a/src/scope.rs
+++ b/src/scope.rs
@@ -103,7 +103,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
{
let func = RefCell::new(func);
self.create_function(move |lua, args| {
- (&mut *func
+ (*func
.try_borrow_mut()
.map_err(|_| Error::RecursiveMutCallback)?)(lua, args)
})
@@ -306,7 +306,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
let mut data = data
.try_borrow_mut()
.map_err(|_| Error::UserDataBorrowMutError)?;
- (&mut *method)(lua, &mut *data, args)
+ (*method)(lua, &mut *data, args)
});
unsafe { scope.create_callback(f) }
}
@@ -314,7 +314,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
NonStaticMethod::FunctionMut(function) => {
let function = RefCell::new(function);
let f = Box::new(move |lua, args| {
- (&mut *function
+ (*function
.try_borrow_mut()
.map_err(|_| Error::RecursiveMutCallback)?)(
lua, args