Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Sep 22, 2024
1 parent 3088516 commit fce8538
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
17 changes: 11 additions & 6 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::any::TypeId;
use std::cell::RefCell;
use std::marker::PhantomData;
use std::ops::Deref;
use std::os::raw::{c_int, c_void};
use std::os::raw::c_int;
use std::panic::Location;
use std::result::Result as StdResult;
use std::{fmt, mem, ptr};
Expand All @@ -18,8 +18,8 @@ use crate::string::String;
use crate::table::Table;
use crate::thread::Thread;
use crate::types::{
AppDataRef, AppDataRefMut, ArcReentrantMutexGuard, Integer, LightUserData, MaybeSend, Number,
ReentrantMutex, ReentrantMutexGuard, RegistryKey, XRc, XWeak,
AppDataRef, AppDataRefMut, ArcReentrantMutexGuard, Integer, MaybeSend, Number, ReentrantMutex,
ReentrantMutexGuard, RegistryKey, XRc, XWeak,
};
use crate::userdata::{AnyUserData, UserData, UserDataProxy, UserDataRegistry, UserDataStorage};
use crate::util::{
Expand All @@ -34,7 +34,10 @@ use crate::hook::HookTriggers;
use crate::{chunk::Compiler, types::VmState};

#[cfg(feature = "async")]
use std::future::{self, Future};
use {
crate::types::LightUserData,
std::future::{self, Future},
};

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

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

// Luau version located in `luau/mod.rs`
Expand Down Expand Up @@ -1874,6 +1878,7 @@ impl Lua {
/// Returns a handle to the unprotected Lua state without any synchronization.
///
/// This is useful where we know that the lock is already held by the caller.
#[cfg(feature = "async")]
#[inline(always)]
pub(crate) unsafe fn raw_lua(&self) -> &RawLua {
&*self.raw.data_ptr()
Expand Down
3 changes: 2 additions & 1 deletion src/state/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::util::{
push_internal_userdata, push_string, push_table, rawset_field, safe_pcall, safe_xpcall, short_type_name,
StackGuard, WrappedFailure,
};
use crate::value::{FromLuaMulti, IntoLua, MultiValue, Nil, Value};
use crate::value::{IntoLua, Nil, Value};

use super::extra::ExtraData;
use super::{Lua, LuaOptions, WeakLua};
Expand All @@ -38,6 +38,7 @@ use crate::hook::{Debug, HookTriggers};
#[cfg(feature = "async")]
use {
crate::types::{AsyncCallback, AsyncCallbackUpvalue, AsyncPollUpvalue},
crate::value::{FromLuaMulti, MultiValue},
std::ptr::NonNull,
std::task::{Context, Poll, Waker},
};
Expand Down
16 changes: 8 additions & 8 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ impl String {

unsafe fn to_slice(&self) -> (&[u8], Lua) {
let lua = self.0.lua.upgrade();
let rawlua = lua.lock();
let ref_thread = rawlua.ref_thread();
unsafe {
let slice = unsafe {
let rawlua = lua.lock();
let ref_thread = rawlua.ref_thread();

mlua_debug_assert!(
ffi::lua_type(ref_thread, self.0.index) == ffi::LUA_TSTRING,
"string ref is not string type"
);

let mut size = 0;
// This will not trigger a 'm' error, because the reference is guaranteed to be of
// string type
let mut size = 0;
let data = ffi::lua_tolstring(ref_thread, self.0.index, &mut size);

drop(rawlua);
(slice::from_raw_parts(data as *const u8, size + 1), lua)
}
slice::from_raw_parts(data as *const u8, size + 1)
};
(slice, lua)
}

/// Converts this string to a generic C pointer.
Expand Down
2 changes: 1 addition & 1 deletion src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Thread {
let state = lua.state();
let thread_state = self.state();

let nargs = args.push_into_stack_multi(&lua)?;
let nargs = args.push_into_stack_multi(lua)?;
if nargs > 0 {
check_stack(thread_state, nargs)?;
ffi::lua_xmove(state, thread_state, nargs);
Expand Down
4 changes: 2 additions & 2 deletions src/userdata/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::ser::{Serialize, Serializer};

use crate::error::{Error, Result};
use crate::state::{Lua, RawLua};
use crate::types::{MaybeSend, XRc};
use crate::types::XRc;
use crate::userdata::AnyUserData;
use crate::util::get_userdata;
use crate::value::{FromLua, Value};
Expand Down Expand Up @@ -391,7 +391,7 @@ impl<T: 'static> UserDataStorage<T> {
#[inline(always)]
pub(crate) fn new_ser(data: T) -> Self
where
T: Serialize + MaybeSend,
T: Serialize + crate::types::MaybeSend,
{
let data = Box::new(data) as Box<DynSerialize>;
Self::Owned(UserDataVariant::Serializable(XRc::new(UserDataCell::new(data))))
Expand Down
6 changes: 2 additions & 4 deletions src/userdata/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ use std::string::String as StdString;
use crate::error::{Error, Result};
use crate::state::{Lua, RawLua};
use crate::types::{Callback, MaybeSend};
use crate::userdata::{
AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataRef, UserDataRefMut,
UserDataStorage,
};
use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataStorage};
use crate::util::{get_userdata, short_type_name};
use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value};

#[cfg(feature = "async")]
use {
crate::types::AsyncCallback,
crate::userdata::{UserDataRef, UserDataRefMut},
std::future::{self, Future},
};

Expand Down
11 changes: 6 additions & 5 deletions src/value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::{vec_deque, HashSet, VecDeque};
use std::ops::{Deref, DerefMut};
Expand All @@ -24,12 +23,14 @@ use {
crate::table::SerializableTable,
rustc_hash::FxHashSet,
serde::ser::{self, Serialize, Serializer},
std::{rc::Rc, result::Result as StdResult},
std::{cell::RefCell, rc::Rc, result::Result as StdResult},
};

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

0 comments on commit fce8538

Please sign in to comment.