diff options
| -rwxr-xr-x | src/collection/boxed.rs | 6 | ||||
| -rwxr-xr-x | src/collection/owned.rs | 4 | ||||
| -rwxr-xr-x | src/collection/ref.rs | 4 | ||||
| -rwxr-xr-x | src/collection/retry.rs | 53 | ||||
| -rw-r--r-- | src/iterator/guard.rs | 2 | ||||
| -rwxr-xr-x | src/key.rs | 5 | ||||
| -rwxr-xr-x | src/lib.rs | 30 | ||||
| -rwxr-xr-x | src/mutex/guard.rs | 2 | ||||
| -rwxr-xr-x | src/poisonable.rs | 33 | ||||
| -rwxr-xr-x | src/poisonable/guard.rs | 4 | ||||
| -rwxr-xr-x | src/rwlock/read_guard.rs | 2 | ||||
| -rwxr-xr-x | src/rwlock/rwlock.rs | 24 | ||||
| -rwxr-xr-x | src/rwlock/write_guard.rs | 2 | ||||
| -rwxr-xr-x | tests/evil_mutex.rs | 1 | ||||
| -rwxr-xr-x | tests/evil_rwlock.rs | 1 | ||||
| -rwxr-xr-x | tests/evil_try_mutex.rs | 1 | ||||
| -rwxr-xr-x | tests/evil_try_rwlock.rs | 1 | ||||
| -rwxr-xr-x | tests/evil_unlock_mutex.rs | 2 | ||||
| -rwxr-xr-x | tests/evil_unlock_rwlock.rs | 2 |
19 files changed, 99 insertions, 80 deletions
diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs index 83675b5..1478120 100755 --- a/src/collection/boxed.rs +++ b/src/collection/boxed.rs @@ -141,7 +141,7 @@ impl<L: OwnedLockable, I: FromIterator<L> + OwnedLockable> FromIterator<L> } // safety: the RawLocks must be send because they come from the Send Lockable -#[allow(clippy::non_send_fields_in_send_ty)] +#[expect(clippy::non_send_fields_in_send_ty)] unsafe impl<L: Send> Send for BoxedLockCollection<L> {} unsafe impl<L: Sync> Sync for BoxedLockCollection<L> {} @@ -327,7 +327,7 @@ impl<L: Lockable> BoxedLockCollection<L> { locks.sort_by_key(|lock| (&raw const **lock).cast::<()>() as usize); // safety: we're just changing the lifetimes - let locks: Vec<&'static dyn RawLock> = std::mem::transmute(locks); + let locks: Vec<&'static dyn RawLock> = unsafe { std::mem::transmute(locks) }; let data = &raw const *data; Self { child: data, locks } } @@ -821,7 +821,7 @@ mod tests { } #[test] - #[allow(clippy::float_cmp)] + #[expect(clippy::float_cmp)] fn uses_correct_default() { let collection = BoxedLockCollection::<(Mutex<f64>, Mutex<Option<i32>>, Mutex<usize>)>::default(); diff --git a/src/collection/owned.rs b/src/collection/owned.rs index 516f1ea..a7ab1b6 100755 --- a/src/collection/owned.rs +++ b/src/collection/owned.rs @@ -368,7 +368,6 @@ impl<L: OwnedLockable> OwnedLockCollection<L> { /// *guard.1 = "1"; /// let key = OwnedLockCollection::<(Mutex<i32>, Mutex<&str>)>::unlock(guard); /// ``` - #[allow(clippy::missing_const_for_fn)] pub fn unlock(guard: LockGuard<L::Guard<'_>>) -> ThreadKey { drop(guard.guard); guard.key @@ -553,7 +552,6 @@ impl<L: Sharable> OwnedLockCollection<L> { /// let mut guard = lock.read(key); /// let key = OwnedLockCollection::<(RwLock<i32>, RwLock<&str>)>::unlock_read(guard); /// ``` - #[allow(clippy::missing_const_for_fn)] pub fn unlock_read(guard: LockGuard<L::ReadGuard<'_>>) -> ThreadKey { drop(guard.guard); guard.key @@ -790,7 +788,6 @@ mod tests { std::thread::scope(|s| { s.spawn(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused)] let guard = collection.lock(key); std::mem::forget(guard); }); @@ -817,7 +814,6 @@ mod tests { std::thread::scope(|s| { s.spawn(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused)] let guard = collection.lock(key); std::mem::forget(guard); }); diff --git a/src/collection/ref.rs b/src/collection/ref.rs index a995097..a422bb2 100755 --- a/src/collection/ref.rs +++ b/src/collection/ref.rs @@ -123,7 +123,7 @@ impl<L: Debug> Debug for RefLockCollection<'_, L> { } // safety: the RawLocks must be send because they come from the Send Lockable -#[allow(clippy::non_send_fields_in_send_ty)] +#[expect(clippy::non_send_fields_in_send_ty)] unsafe impl<L: Send> Send for RefLockCollection<'_, L> {} unsafe impl<L: Sync> Sync for RefLockCollection<'_, L> {} @@ -418,7 +418,6 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> { /// *guard.1 = "1"; /// let key = RefLockCollection::<(Mutex<i32>, Mutex<&str>)>::unlock(guard); /// ``` - #[allow(clippy::missing_const_for_fn)] pub fn unlock(guard: LockGuard<L::Guard<'_>>) -> ThreadKey { drop(guard.guard); guard.key @@ -604,7 +603,6 @@ impl<L: Sharable> RefLockCollection<'_, L> { /// let mut guard = lock.read(key); /// let key = RefLockCollection::<(RwLock<i32>, RwLock<&str>)>::unlock_read(guard); /// ``` - #[allow(clippy::missing_const_for_fn)] pub fn unlock_read(guard: LockGuard<L::ReadGuard<'_>>) -> ThreadKey { drop(guard.guard); guard.key diff --git a/src/collection/retry.rs b/src/collection/retry.rs index 4a5df6e..b9ac530 100755 --- a/src/collection/retry.rs +++ b/src/collection/retry.rs @@ -154,36 +154,39 @@ unsafe impl<L: Lockable> RawLock for RetryingLockCollection<L> { handle_unwind( || 'outer: loop { // safety: we have the thread key - locks[first_index.get()].raw_read(); - for (i, lock) in locks.iter().enumerate() { - if i == first_index.get() { - continue; - } - - // safety: we have the thread key - if lock.raw_try_read() { - locked.set(locked.get() + 1); - } else { - // safety: we already locked all of these - attempt_to_recover_reads_from_panic(&locks[0..i]); + unsafe { + locks[first_index.get()].raw_read(); - if first_index.get() >= i { - // safety: this is already locked and can't be unlocked - // by the previous loop - locks[first_index.get()].raw_unlock_read(); + for (i, lock) in locks.iter().enumerate() { + if i == first_index.get() { + continue; } - // these are no longer locked - locked.set(0); + // safety: we have the thread key + if lock.raw_try_read() { + locked.set(locked.get() + 1); + } else { + // safety: we already locked all of these + attempt_to_recover_reads_from_panic(&locks[0..i]); + + if first_index.get() >= i { + // safety: this is already locked and can't be unlocked + // by the previous loop + locks[first_index.get()].raw_unlock_read(); + } + + // these are no longer locked + locked.set(0); - // don't go into a spin loop, wait for this one to lock - first_index.set(i); - continue 'outer; + // don't go into a spin loop, wait for this one to lock + first_index.set(i); + continue 'outer; + } } - } - // safety: we locked all the data - break; + // safety: we locked all the data + break; + } }, || { utils::attempt_to_recover_reads_from_panic(&locks[0..locked.get()]); @@ -1019,7 +1022,7 @@ mod tests { } #[test] - #[allow(clippy::float_cmp)] + #[expect(clippy::float_cmp)] fn uses_correct_default() { let collection = RetryingLockCollection::<(RwLock<f64>, Mutex<Option<i32>>, Mutex<usize>)>::default(); diff --git a/src/iterator/guard.rs b/src/iterator/guard.rs index 6393fc2..cb220ac 100644 --- a/src/iterator/guard.rs +++ b/src/iterator/guard.rs @@ -2,7 +2,7 @@ use std::fmt::{Debug, Display}; use std::hash::Hash; use std::ops::{Deref, DerefMut}; -use super::{ConsumedIteratorGuard, IteratorGuard}; +use super::IteratorGuard; #[mutants::skip] // hashing involves RNG and is hard to test #[cfg(not(tarpaulin_include))] @@ -75,9 +75,8 @@ impl ThreadKey { /// ``` #[must_use] pub fn get() -> Option<Self> { - // safety: we just acquired the lock - // safety: if this code changes, check to ensure the requirement for - // the Drop implementation is still true + // if this code changes, check to ensure the requirement for + // the Drop implementation is still true KEY.with(|key| { key.try_lock().then_some(Self { phantom: PhantomData, @@ -1,5 +1,35 @@ #![warn(clippy::pedantic)] #![warn(clippy::nursery)] +#![warn(clippy::cargo)] +#![warn(clippy::allow_attributes)] +#![warn(clippy::as_pointer_underscore)] +#![warn(clippy::cognitive_complexity)] +#![warn(clippy::dbg_macro)] +#![warn(clippy::error_impl_error)] +#![warn(clippy::exit)] +#![warn(clippy::fn_to_numeric_cast_any)] +#![warn(clippy::infinite_loop)] +#![warn(clippy::lossy_float_literal)] +#![warn(clippy::mixed_read_write_in_expression)] +#![warn(clippy::mod_module_files)] +#![warn(clippy::needless_raw_strings)] +#![warn(clippy::non_zero_suggestions)] +#![warn(clippy::print_stdout)] +#![warn(clippy::print_stderr)] +#![warn(clippy::redundant_test_prefix)] +#![warn(clippy::redundant_type_annotations)] +#![warn(clippy::string_add)] +#![warn(clippy::string_lit_chars_any)] +#![warn(clippy::tests_outside_test_module)] +#![warn(clippy::todo)] +#![warn(clippy::try_err)] +#![warn(clippy::unimplemented)] +#![warn(clippy::unnecessary_safety_comment)] +#![warn(clippy::unnecessary_safety_doc)] +#![warn(clippy::unseparated_literal_suffix)] +#![warn(clippy::unused_result_ok)] +#![warn(clippy::unused_trait_names)] +#![warn(clippy::unwrap_in_result)] #![allow(clippy::module_name_repetitions)] #![allow(clippy::declare_interior_mutable_const)] #![allow(clippy::semicolon_if_nothing_returned)] diff --git a/src/mutex/guard.rs b/src/mutex/guard.rs index d88fded..538a08a 100755 --- a/src/mutex/guard.rs +++ b/src/mutex/guard.rs @@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut}; use lock_api::RawMutex; -use crate::lockable::RawLock; +use crate::lockable::RawLock as _; use crate::ThreadKey; use super::{Mutex, MutexGuard, MutexRef}; diff --git a/src/poisonable.rs b/src/poisonable.rs index ac0e1bf..8dada90 100755 --- a/src/poisonable.rs +++ b/src/poisonable.rs @@ -140,7 +140,7 @@ mod tests { use std::sync::Arc; use super::*; - use crate::lockable::Lockable; + use crate::lockable::Lockable as _; use crate::{LockCollection, Mutex, RwLock, ThreadKey}; #[test] @@ -156,7 +156,7 @@ mod tests { assert_eq!(**guard, 42); panic!(); - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard1); }) .join() @@ -181,7 +181,7 @@ mod tests { assert_eq!(**guard, 42); panic!(); - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard1); }) .join() @@ -207,10 +207,10 @@ mod tests { let _ = std::panic::catch_unwind(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused_variables)] + #[expect(unused_variables)] let guard = mutex.lock(key); panic!(); - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard); }); @@ -231,10 +231,10 @@ mod tests { std::panic::catch_unwind(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused_variables)] + #[expect(unused_variables)] let guard = mutex.lock(key); panic!(); - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard); }) .unwrap_err(); @@ -255,10 +255,10 @@ mod tests { std::panic::catch_unwind(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused_variables)] + #[expect(unused_variables)] let guard = mutex.lock(key); panic!(); - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard); }) .unwrap_err(); @@ -527,12 +527,11 @@ mod tests { let _ = std::panic::catch_unwind(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused_variables)] + #[expect(unused_variables)] let guard = mutex.lock(key); panic!(); - #[allow(unknown_lints)] - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard); }); @@ -549,12 +548,11 @@ mod tests { let _ = std::panic::catch_unwind(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused_variables)] + #[expect(unused_variables)] let guard = mutex.lock(key); panic!(); - #[allow(unknown_lints)] - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard); }); @@ -577,12 +575,11 @@ mod tests { let _ = std::panic::catch_unwind(|| { let key = ThreadKey::get().unwrap(); - #[allow(unused_variables)] + #[expect(unused_variables)] let guard = mutex.lock(key); panic!(); - #[allow(unknown_lints)] - #[allow(unreachable_code)] + #[expect(unreachable_code)] drop(guard); }); diff --git a/src/poisonable/guard.rs b/src/poisonable/guard.rs index b887e2d..32b4ee8 100755 --- a/src/poisonable/guard.rs +++ b/src/poisonable/guard.rs @@ -100,14 +100,14 @@ impl<T, Guard: Deref<Target = T>> Deref for PoisonGuard<'_, Guard> { type Target = T; fn deref(&self) -> &Self::Target { - #[allow(clippy::explicit_auto_deref)] // fixing this results in a compiler error + #[expect(clippy::explicit_auto_deref)] // fixing this results in a compiler error &*self.guard.guard } } impl<T, Guard: DerefMut<Target = T>> DerefMut for PoisonGuard<'_, Guard> { fn deref_mut(&mut self) -> &mut Self::Target { - #[allow(clippy::explicit_auto_deref)] // fixing this results in a compiler error + #[expect(clippy::explicit_auto_deref)] // fixing this results in a compiler error &mut *self.guard.guard } } diff --git a/src/rwlock/read_guard.rs b/src/rwlock/read_guard.rs index 5b26c06..f3161f5 100755 --- a/src/rwlock/read_guard.rs +++ b/src/rwlock/read_guard.rs @@ -5,7 +5,7 @@ use std::ops::Deref; use lock_api::RawRwLock; -use crate::lockable::RawLock; +use crate::lockable::RawLock as _; use crate::ThreadKey; use super::{RwLock, RwLockReadGuard, RwLockReadRef}; diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index b93d8e2..6adf73a 100755 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -573,11 +573,13 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> { /// Attempts to create a shared lock without a key. Locking this without /// exclusive access to the key is undefined behavior. pub(crate) unsafe fn try_read_no_key(&self) -> Option<RwLockReadRef<'_, T, R>> { - if self.raw_try_read() { - // safety: the lock is locked first - Some(RwLockReadRef(self, PhantomData)) - } else { - None + unsafe { + if self.raw_try_read() { + // safety: the lock is locked first + Some(RwLockReadRef(self, PhantomData)) + } else { + None + } } } @@ -585,11 +587,13 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> { /// without exclusive access to the key is undefined behavior. #[cfg(test)] pub(crate) unsafe fn try_write_no_key(&self) -> Option<RwLockWriteRef<'_, T, R>> { - if self.raw_try_write() { - // safety: the lock is locked first - Some(RwLockWriteRef(self, PhantomData)) - } else { - None + unsafe { + if self.raw_try_write() { + // safety: the lock is locked first + Some(RwLockWriteRef(self, PhantomData)) + } else { + None + } } } diff --git a/src/rwlock/write_guard.rs b/src/rwlock/write_guard.rs index c7676b5..823f7a4 100755 --- a/src/rwlock/write_guard.rs +++ b/src/rwlock/write_guard.rs @@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut}; use lock_api::RawRwLock; -use crate::lockable::RawLock; +use crate::lockable::RawLock as _; use crate::ThreadKey; use super::{RwLock, RwLockWriteGuard, RwLockWriteRef}; diff --git a/tests/evil_mutex.rs b/tests/evil_mutex.rs index e10acc8..ef6f31a 100755 --- a/tests/evil_mutex.rs +++ b/tests/evil_mutex.rs @@ -10,7 +10,6 @@ struct EvilMutex { } unsafe impl RawMutex for EvilMutex { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self { inner: parking_lot::RawMutex::INIT, }; diff --git a/tests/evil_rwlock.rs b/tests/evil_rwlock.rs index 4be86a1..a57a27a 100755 --- a/tests/evil_rwlock.rs +++ b/tests/evil_rwlock.rs @@ -11,7 +11,6 @@ struct EvilRwLock { } unsafe impl RawRwLock for EvilRwLock { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self { inner: parking_lot::RawRwLock::INIT, }; diff --git a/tests/evil_try_mutex.rs b/tests/evil_try_mutex.rs index 5c31a91..22834be 100755 --- a/tests/evil_try_mutex.rs +++ b/tests/evil_try_mutex.rs @@ -12,7 +12,6 @@ struct EvilMutex { } unsafe impl RawMutex for EvilMutex { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self { inner: parking_lot::RawMutex::INIT, }; diff --git a/tests/evil_try_rwlock.rs b/tests/evil_try_rwlock.rs index b00a666..acba794 100755 --- a/tests/evil_try_rwlock.rs +++ b/tests/evil_try_rwlock.rs @@ -10,7 +10,6 @@ struct EvilRwLock { } unsafe impl RawRwLock for EvilRwLock { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self { inner: parking_lot::RawRwLock::INIT, }; diff --git a/tests/evil_unlock_mutex.rs b/tests/evil_unlock_mutex.rs index ee12abc..c21fc34 100755 --- a/tests/evil_unlock_mutex.rs +++ b/tests/evil_unlock_mutex.rs @@ -12,7 +12,6 @@ struct KindaEvilMutex { struct EvilMutex {} unsafe impl RawMutex for KindaEvilMutex { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self { inner: parking_lot::RawMutex::INIT, }; @@ -33,7 +32,6 @@ unsafe impl RawMutex for KindaEvilMutex { } unsafe impl RawMutex for EvilMutex { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self {}; type GuardMarker = GuardNoSend; diff --git a/tests/evil_unlock_rwlock.rs b/tests/evil_unlock_rwlock.rs index 58402c9..577de85 100755 --- a/tests/evil_unlock_rwlock.rs +++ b/tests/evil_unlock_rwlock.rs @@ -12,7 +12,6 @@ struct KindaEvilRwLock { struct EvilRwLock {} unsafe impl RawRwLock for KindaEvilRwLock { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self { inner: parking_lot::RawRwLock::INIT, }; @@ -45,7 +44,6 @@ unsafe impl RawRwLock for KindaEvilRwLock { } unsafe impl RawRwLock for EvilRwLock { - #[allow(clippy::declare_interior_mutable_const)] const INIT: Self = Self {}; type GuardMarker = GuardNoSend; |
