Skip to content

Commit fce8538

Browse files
committed
Fix clippy warnings
1 parent 3088516 commit fce8538

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

src/state.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::TypeId;
22
use std::cell::RefCell;
33
use std::marker::PhantomData;
44
use std::ops::Deref;
5-
use std::os::raw::{c_int, c_void};
5+
use std::os::raw::c_int;
66
use std::panic::Location;
77
use std::result::Result as StdResult;
88
use std::{fmt, mem, ptr};
@@ -18,8 +18,8 @@ use crate::string::String;
1818
use crate::table::Table;
1919
use crate::thread::Thread;
2020
use crate::types::{
21-
AppDataRef, AppDataRefMut, ArcReentrantMutexGuard, Integer, LightUserData, MaybeSend, Number,
22-
ReentrantMutex, ReentrantMutexGuard, RegistryKey, XRc, XWeak,
21+
AppDataRef, AppDataRefMut, ArcReentrantMutexGuard, Integer, MaybeSend, Number, ReentrantMutex,
22+
ReentrantMutexGuard, RegistryKey, XRc, XWeak,
2323
};
2424
use crate::userdata::{AnyUserData, UserData, UserDataProxy, UserDataRegistry, UserDataStorage};
2525
use crate::util::{
@@ -34,7 +34,10 @@ use crate::hook::HookTriggers;
3434
use crate::{chunk::Compiler, types::VmState};
3535

3636
#[cfg(feature = "async")]
37-
use std::future::{self, Future};
37+
use {
38+
crate::types::LightUserData,
39+
std::future::{self, Future},
40+
};
3841

3942
#[cfg(feature = "serialize")]
4043
use serde::Serialize;
@@ -284,6 +287,7 @@ impl Lua {
284287
///
285288
/// This method ensures that the Lua instance is locked while the function is called
286289
/// and restores Lua stack after the function returns.
290+
#[allow(clippy::missing_safety_doc)]
287291
pub unsafe fn with_raw_state<R: FromLuaMulti>(
288292
&self,
289293
args: impl IntoLuaMulti,
@@ -648,7 +652,7 @@ impl Lua {
648652
F: Fn(&Lua, &str, bool) -> Result<()> + MaybeSend + 'static,
649653
{
650654
use std::ffi::CStr;
651-
use std::os::raw::c_char;
655+
use std::os::raw::{c_char, c_void};
652656
use std::string::String as StdString;
653657

654658
unsafe extern "C-unwind" fn warn_proc(ud: *mut c_void, msg: *const c_char, tocont: c_int) {
@@ -1825,7 +1829,7 @@ impl Lua {
18251829
#[inline(always)]
18261830
pub fn poll_pending() -> LightUserData {
18271831
static ASYNC_POLL_PENDING: u8 = 0;
1828-
LightUserData(&ASYNC_POLL_PENDING as *const u8 as *mut c_void)
1832+
LightUserData(&ASYNC_POLL_PENDING as *const u8 as *mut std::os::raw::c_void)
18291833
}
18301834

18311835
// Luau version located in `luau/mod.rs`
@@ -1874,6 +1878,7 @@ impl Lua {
18741878
/// Returns a handle to the unprotected Lua state without any synchronization.
18751879
///
18761880
/// This is useful where we know that the lock is already held by the caller.
1881+
#[cfg(feature = "async")]
18771882
#[inline(always)]
18781883
pub(crate) unsafe fn raw_lua(&self) -> &RawLua {
18791884
&*self.raw.data_ptr()

src/state/raw.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::util::{
2727
push_internal_userdata, push_string, push_table, rawset_field, safe_pcall, safe_xpcall, short_type_name,
2828
StackGuard, WrappedFailure,
2929
};
30-
use crate::value::{FromLuaMulti, IntoLua, MultiValue, Nil, Value};
30+
use crate::value::{IntoLua, Nil, Value};
3131

3232
use super::extra::ExtraData;
3333
use super::{Lua, LuaOptions, WeakLua};
@@ -38,6 +38,7 @@ use crate::hook::{Debug, HookTriggers};
3838
#[cfg(feature = "async")]
3939
use {
4040
crate::types::{AsyncCallback, AsyncCallbackUpvalue, AsyncPollUpvalue},
41+
crate::value::{FromLuaMulti, MultiValue},
4142
std::ptr::NonNull,
4243
std::task::{Context, Poll, Waker},
4344
};

src/string.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@ impl String {
105105

106106
unsafe fn to_slice(&self) -> (&[u8], Lua) {
107107
let lua = self.0.lua.upgrade();
108-
let rawlua = lua.lock();
109-
let ref_thread = rawlua.ref_thread();
110-
unsafe {
108+
let slice = unsafe {
109+
let rawlua = lua.lock();
110+
let ref_thread = rawlua.ref_thread();
111+
111112
mlua_debug_assert!(
112113
ffi::lua_type(ref_thread, self.0.index) == ffi::LUA_TSTRING,
113114
"string ref is not string type"
114115
);
115116

116-
let mut size = 0;
117117
// This will not trigger a 'm' error, because the reference is guaranteed to be of
118118
// string type
119+
let mut size = 0;
119120
let data = ffi::lua_tolstring(ref_thread, self.0.index, &mut size);
120-
121-
drop(rawlua);
122-
(slice::from_raw_parts(data as *const u8, size + 1), lua)
123-
}
121+
slice::from_raw_parts(data as *const u8, size + 1)
122+
};
123+
(slice, lua)
124124
}
125125

126126
/// Converts this string to a generic C pointer.

src/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Thread {
143143
let state = lua.state();
144144
let thread_state = self.state();
145145

146-
let nargs = args.push_into_stack_multi(&lua)?;
146+
let nargs = args.push_into_stack_multi(lua)?;
147147
if nargs > 0 {
148148
check_stack(thread_state, nargs)?;
149149
ffi::lua_xmove(state, thread_state, nargs);

src/userdata/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::ser::{Serialize, Serializer};
99

1010
use crate::error::{Error, Result};
1111
use crate::state::{Lua, RawLua};
12-
use crate::types::{MaybeSend, XRc};
12+
use crate::types::XRc;
1313
use crate::userdata::AnyUserData;
1414
use crate::util::get_userdata;
1515
use crate::value::{FromLua, Value};
@@ -391,7 +391,7 @@ impl<T: 'static> UserDataStorage<T> {
391391
#[inline(always)]
392392
pub(crate) fn new_ser(data: T) -> Self
393393
where
394-
T: Serialize + MaybeSend,
394+
T: Serialize + crate::types::MaybeSend,
395395
{
396396
let data = Box::new(data) as Box<DynSerialize>;
397397
Self::Owned(UserDataVariant::Serializable(XRc::new(UserDataCell::new(data))))

src/userdata/registry.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ use std::string::String as StdString;
99
use crate::error::{Error, Result};
1010
use crate::state::{Lua, RawLua};
1111
use crate::types::{Callback, MaybeSend};
12-
use crate::userdata::{
13-
AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataRef, UserDataRefMut,
14-
UserDataStorage,
15-
};
12+
use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataStorage};
1613
use crate::util::{get_userdata, short_type_name};
1714
use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value};
1815

1916
#[cfg(feature = "async")]
2017
use {
2118
crate::types::AsyncCallback,
19+
crate::userdata::{UserDataRef, UserDataRefMut},
2220
std::future::{self, Future},
2321
};
2422

src/value.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::cell::RefCell;
21
use std::cmp::Ordering;
32
use std::collections::{vec_deque, HashSet, VecDeque};
43
use std::ops::{Deref, DerefMut};
@@ -24,12 +23,14 @@ use {
2423
crate::table::SerializableTable,
2524
rustc_hash::FxHashSet,
2625
serde::ser::{self, Serialize, Serializer},
27-
std::{rc::Rc, result::Result as StdResult},
26+
std::{cell::RefCell, rc::Rc, result::Result as StdResult},
2827
};
2928

30-
/// A dynamically typed Lua value. The `String`, `Table`, `Function`, `Thread`, and `UserData`
31-
/// variants contain handle types into the internal Lua state. It is a logic error to mix handle
32-
/// types between separate `Lua` instances, and doing so will result in a panic.
29+
/// A dynamically typed Lua value.
30+
///
31+
/// The `String`, `Table`, `Function`, `Thread`, and `UserData` variants contain handle types
32+
/// into the internal Lua state. It is a logic error to mix handle types between separate
33+
/// `Lua` instances, and doing so will result in a panic.
3334
#[derive(Clone)]
3435
pub enum Value {
3536
/// The Lua value `nil`.

0 commit comments

Comments
 (0)