Skip to content

Commit 5ab9766

Browse files
committed
Fix clippy warnings
1 parent e706ae4 commit 5ab9766

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ erased-serde = { version = "0.4", optional = true }
5757
serde-value = { version = "0.7", optional = true }
5858
parking_lot = { version = "0.12", features = ["arc_lock"] }
5959
anyhow = { version = "1.0", optional = true }
60+
rustversion = "1.0"
6061

6162
ffi = { package = "mlua-sys", version = "0.6.6", path = "mlua-sys" }
6263

src/memory.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,31 @@ pub(crate) struct MemoryState {
1818
}
1919

2020
impl MemoryState {
21+
#[cfg(feature = "luau")]
2122
#[inline]
2223
pub(crate) unsafe fn get(state: *mut ffi::lua_State) -> *mut Self {
2324
let mut mem_state = ptr::null_mut();
24-
#[cfg(feature = "luau")]
25-
{
26-
ffi::lua_getallocf(state, &mut mem_state);
27-
mlua_assert!(!mem_state.is_null(), "Luau state has no allocator userdata");
25+
ffi::lua_getallocf(state, &mut mem_state);
26+
mlua_assert!(!mem_state.is_null(), "Luau state has no allocator userdata");
27+
mem_state as *mut MemoryState
28+
}
29+
30+
#[cfg(not(feature = "luau"))]
31+
#[rustversion::since(1.85)]
32+
#[inline]
33+
pub(crate) unsafe fn get(state: *mut ffi::lua_State) -> *mut Self {
34+
let mut mem_state = ptr::null_mut();
35+
if !ptr::fn_addr_eq(ffi::lua_getallocf(state, &mut mem_state), ALLOCATOR) {
36+
mem_state = ptr::null_mut();
2837
}
29-
#[cfg(not(feature = "luau"))]
38+
mem_state as *mut MemoryState
39+
}
40+
41+
#[cfg(not(feature = "luau"))]
42+
#[rustversion::before(1.85)]
43+
#[inline]
44+
pub(crate) unsafe fn get(state: *mut ffi::lua_State) -> *mut Self {
45+
let mut mem_state = ptr::null_mut();
3046
if ffi::lua_getallocf(state, &mut mem_state) != ALLOCATOR {
3147
mem_state = ptr::null_mut();
3248
}

src/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1809,8 +1809,8 @@ impl Lua {
18091809
let state = lua.state();
18101810
unsafe {
18111811
let mut unref_list = (*lua.extra.get()).registry_unref_list.lock();
1812-
let unref_list = mem::replace(&mut *unref_list, Some(Vec::new()));
1813-
for id in mlua_expect!(unref_list, "unref list not set") {
1812+
let unref_list = unref_list.replace(Vec::new());
1813+
for id in mlua_expect!(unref_list, "unref list is not set") {
18141814
ffi::luaL_unref(state, ffi::LUA_REGISTRYINDEX, id);
18151815
}
18161816
}

0 commit comments

Comments
 (0)