Skip to content

Commit

Permalink
Mark MutexGuard with #[clippy::has_significant_drop] (#37)
Browse files Browse the repository at this point in the history
* Mark `MutexGuard` with `#[clippy::has_significant_drop]`

`#[clippy::has_significant_drop]` tells that a structure should be considered when evaluating some lints. Examples of such behavior are the existent `clippy::significant_drop_in_scrutinee` and in the soon-to-be-finished rust-lang/rust-clippy#9399.

* Include more structures
  • Loading branch information
c410-f3r authored Feb 3, 2023
1 parent 350cda0 commit 39e0b6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ impl<T: ?Sized, B: Borrow<Mutex<T>>> Drop for AcquireSlow<B, T> {
}

/// A guard that releases the mutex when dropped.
#[clippy::has_significant_drop]
pub struct MutexGuard<'a, T: ?Sized>(&'a Mutex<T>);

unsafe impl<T: Send + ?Sized> Send for MutexGuard<'_, T> {}
Expand Down Expand Up @@ -595,6 +596,7 @@ impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
}

/// An owned guard that releases the mutex when dropped.
#[clippy::has_significant_drop]
pub struct MutexGuardArc<T: ?Sized>(Arc<Mutex<T>>);

unsafe impl<T: Send + ?Sized> Send for MutexGuardArc<T> {}
Expand Down
3 changes: 3 additions & 0 deletions src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ impl<'a, T: ?Sized> Future for Write<'a, T> {
}

/// A guard that releases the read lock when dropped.
#[clippy::has_significant_drop]
pub struct RwLockReadGuard<'a, T: ?Sized>(&'a RwLock<T>);

unsafe impl<T: Sync + ?Sized> Send for RwLockReadGuard<'_, T> {}
Expand Down Expand Up @@ -640,6 +641,7 @@ impl<T: ?Sized> Deref for RwLockReadGuard<'_, T> {
}

/// A guard that releases the upgradable read lock when dropped.
#[clippy::has_significant_drop]
pub struct RwLockUpgradableReadGuard<'a, T: ?Sized> {
reader: RwLockReadGuard<'a, T>,
reserved: MutexGuard<'a, ()>,
Expand Down Expand Up @@ -851,6 +853,7 @@ impl<T: ?Sized> Drop for RwLockWriteGuardInner<'_, T> {
}

/// A guard that releases the write lock when dropped.
#[clippy::has_significant_drop]
pub struct RwLockWriteGuard<'a, T: ?Sized> {
writer: RwLockWriteGuardInner<'a, T>,
reserved: MutexGuard<'a, ()>,
Expand Down
2 changes: 2 additions & 0 deletions src/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl Future for AcquireArc {
}

/// A guard that releases the acquired permit.
#[clippy::has_significant_drop]
#[derive(Debug)]
pub struct SemaphoreGuard<'a>(&'a Semaphore);

Expand All @@ -255,6 +256,7 @@ impl Drop for SemaphoreGuard<'_> {
}

/// An owned guard that releases the acquired permit.
#[clippy::has_significant_drop]
#[derive(Debug)]
pub struct SemaphoreGuardArc(Arc<Semaphore>);

Expand Down

0 comments on commit 39e0b6d

Please sign in to comment.