From 85dd2106bdc3476c0eb73c97f2f4b338a3486749 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Fri, 20 Dec 2024 18:28:08 -0500 Subject: Fix clippy issues --- src/lockable.rs | 128 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 28 deletions(-) (limited to 'src/lockable.rs') diff --git a/src/lockable.rs b/src/lockable.rs index a2248bc..0066cb4 100644 --- a/src/lockable.rs +++ b/src/lockable.rs @@ -14,7 +14,7 @@ use lock_api::{RawMutex, RawRwLock}; /// A deadlock must never occur. The `unlock` method must correctly unlock the /// data. The `get_ptrs` method must be implemented correctly. The `Output` /// must be unlocked when it is dropped. - +// // Why not use a RawRwLock? Because that would be semantically incorrect, and I // don't want an INIT or GuardMarker associated item. // Originally, RawLock had a sister trait: RawSharableLock. I removed it @@ -262,8 +262,14 @@ unsafe impl RawLock for RwLock { } unsafe impl Lockable for Mutex { - type Guard<'g> = MutexRef<'g, T, R> where Self: 'g; - type ReadGuard<'g> = MutexRef<'g, T, R> where Self: 'g; + type Guard<'g> + = MutexRef<'g, T, R> + where + Self: 'g; + type ReadGuard<'g> + = MutexRef<'g, T, R> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { ptrs.push(self); @@ -279,9 +285,15 @@ unsafe impl Lockable for Mutex { } unsafe impl Lockable for RwLock { - type Guard<'g> = RwLockWriteRef<'g, T, R> where Self: 'g; + type Guard<'g> + = RwLockWriteRef<'g, T, R> + where + Self: 'g; - type ReadGuard<'g> = RwLockReadRef<'g, T, R> where Self: 'g; + type ReadGuard<'g> + = RwLockReadRef<'g, T, R> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { ptrs.push(self); @@ -305,7 +317,10 @@ impl LockableIntoInner for Mutex { } impl LockableAsMut for Mutex { - type Inner<'a> = &'a mut T where Self: 'a; + type Inner<'a> + = &'a mut T + where + Self: 'a; fn as_mut(&mut self) -> Self::Inner<'_> { self.get_mut() @@ -321,7 +336,10 @@ impl LockableIntoInner for RwLock { } impl LockableAsMut for RwLock { - type Inner<'a> = &'a mut T where Self: 'a; + type Inner<'a> + = &'a mut T + where + Self: 'a; fn as_mut(&mut self) -> Self::Inner<'_> { AsMut::as_mut(self) @@ -334,10 +352,16 @@ unsafe impl OwnedLockable for Mutex {} unsafe impl OwnedLockable for RwLock {} -unsafe impl<'l, T: Send, R: RawRwLock + Send + Sync> Lockable for ReadLock<'l, T, R> { - type Guard<'g> = RwLockReadRef<'g, T, R> where Self: 'g; +unsafe impl Lockable for ReadLock<'_, T, R> { + type Guard<'g> + = RwLockReadRef<'g, T, R> + where + Self: 'g; - type ReadGuard<'g> = RwLockReadRef<'g, T, R> where Self: 'g; + type ReadGuard<'g> + = RwLockReadRef<'g, T, R> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { ptrs.push(self.as_ref()); @@ -352,10 +376,16 @@ unsafe impl<'l, T: Send, R: RawRwLock + Send + Sync> Lockable for ReadLock<'l, T } } -unsafe impl<'l, T: Send, R: RawRwLock + Send + Sync> Lockable for WriteLock<'l, T, R> { - type Guard<'g> = RwLockWriteRef<'g, T, R> where Self: 'g; +unsafe impl Lockable for WriteLock<'_, T, R> { + type Guard<'g> + = RwLockWriteRef<'g, T, R> + where + Self: 'g; - type ReadGuard<'g> = RwLockWriteRef<'g, T, R> where Self: 'g; + type ReadGuard<'g> + = RwLockWriteRef<'g, T, R> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { ptrs.push(self.as_ref()); @@ -372,15 +402,21 @@ unsafe impl<'l, T: Send, R: RawRwLock + Send + Sync> Lockable for WriteLock<'l, // Technically, the exclusive locks can also be shared, but there's currently // no way to express that. I don't think I want to ever express that. -unsafe impl<'l, T: Send, R: RawRwLock + Send + Sync> Sharable for ReadLock<'l, T, R> {} +unsafe impl Sharable for ReadLock<'_, T, R> {} // Because both ReadLock and WriteLock hold references to RwLocks, they can't // implement OwnedLockable unsafe impl Lockable for &T { - type Guard<'g> = T::Guard<'g> where Self: 'g; + type Guard<'g> + = T::Guard<'g> + where + Self: 'g; - type ReadGuard<'g> = T::ReadGuard<'g> where Self: 'g; + type ReadGuard<'g> + = T::ReadGuard<'g> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { (*self).get_ptrs(ptrs); @@ -398,9 +434,15 @@ unsafe impl Lockable for &T { unsafe impl Sharable for &T {} unsafe impl Lockable for &mut T { - type Guard<'g> = T::Guard<'g> where Self: 'g; + type Guard<'g> + = T::Guard<'g> + where + Self: 'g; - type ReadGuard<'g> = T::ReadGuard<'g> where Self: 'g; + type ReadGuard<'g> + = T::ReadGuard<'g> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { (**self).get_ptrs(ptrs) @@ -416,7 +458,10 @@ unsafe impl Lockable for &mut T { } impl LockableAsMut for &mut T { - type Inner<'a> = T::Inner<'a> where Self: 'a; + type Inner<'a> + = T::Inner<'a> + where + Self: 'a; fn as_mut(&mut self) -> Self::Inner<'_> { (*self).as_mut() @@ -482,9 +527,15 @@ tuple_impls!(A B C D E F, 0 1 2 3 4 5); tuple_impls!(A B C D E F G, 0 1 2 3 4 5 6); unsafe impl Lockable for [T; N] { - type Guard<'g> = [T::Guard<'g>; N] where Self: 'g; + type Guard<'g> + = [T::Guard<'g>; N] + where + Self: 'g; - type ReadGuard<'g> = [T::ReadGuard<'g>; N] where Self: 'g; + type ReadGuard<'g> + = [T::ReadGuard<'g>; N] + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { for lock in self { @@ -514,9 +565,15 @@ unsafe impl Lockable for [T; N] { } unsafe impl Lockable for Box<[T]> { - type Guard<'g> = Box<[T::Guard<'g>]> where Self: 'g; + type Guard<'g> + = Box<[T::Guard<'g>]> + where + Self: 'g; - type ReadGuard<'g> = Box<[T::ReadGuard<'g>]> where Self: 'g; + type ReadGuard<'g> + = Box<[T::ReadGuard<'g>]> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { for lock in self.iter() { @@ -535,9 +592,15 @@ unsafe impl Lockable for Box<[T]> { unsafe impl Lockable for Vec { // There's no reason why I'd ever want to extend a list of lock guards - type Guard<'g> = Box<[T::Guard<'g>]> where Self: 'g; + type Guard<'g> + = Box<[T::Guard<'g>]> + where + Self: 'g; - type ReadGuard<'g> = Box<[T::ReadGuard<'g>]> where Self: 'g; + type ReadGuard<'g> + = Box<[T::ReadGuard<'g>]> + where + Self: 'g; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { for lock in self { @@ -558,7 +621,10 @@ unsafe impl Lockable for Vec { // but I think that'd require sealing up this trait impl LockableAsMut for [T; N] { - type Inner<'a> = [T::Inner<'a>; N] where Self: 'a; + type Inner<'a> + = [T::Inner<'a>; N] + where + Self: 'a; fn as_mut(&mut self) -> Self::Inner<'_> { unsafe { @@ -588,7 +654,10 @@ impl LockableIntoInner for [T; N] { } impl LockableAsMut for Box<[T]> { - type Inner<'a> = Box<[T::Inner<'a>]> where Self: 'a; + type Inner<'a> + = Box<[T::Inner<'a>]> + where + Self: 'a; fn as_mut(&mut self) -> Self::Inner<'_> { self.iter_mut().map(LockableAsMut::as_mut).collect() @@ -598,7 +667,10 @@ impl LockableAsMut for Box<[T]> { // TODO: using edition 2024, impl LockableIntoInner for Box<[T]> impl LockableAsMut for Vec { - type Inner<'a> = Box<[T::Inner<'a>]> where Self: 'a; + type Inner<'a> + = Box<[T::Inner<'a>]> + where + Self: 'a; fn as_mut(&mut self) -> Self::Inner<'_> { self.iter_mut().map(LockableAsMut::as_mut).collect() -- cgit v1.2.3