From f8a1a6e6ca66e9db42776711acad0a9664a43236 Mon Sep 17 00:00:00 2001 From: Caio Date: Thu, 2 Feb 2023 11:14:55 -0300 Subject: [PATCH 1/3] 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 https://github.com/rust-lang/rust-clippy/issues/9399. --- tokio/src/sync/mutex.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tokio/src/sync/mutex.rs b/tokio/src/sync/mutex.rs index 024755c83b5..f29257b177e 100644 --- a/tokio/src/sync/mutex.rs +++ b/tokio/src/sync/mutex.rs @@ -141,6 +141,7 @@ pub struct Mutex { /// /// The lock is automatically released whenever the guard is dropped, at which /// point `lock` will succeed yet again. +#[clippy::has_significant_drop] #[must_use = "if unused the Mutex will immediately unlock"] pub struct MutexGuard<'a, T: ?Sized> { #[cfg(all(tokio_unstable, feature = "tracing"))] From 41dc5864bb14fd5ddd6369f8852310452356b383 Mon Sep 17 00:00:00 2001 From: Caio Date: Fri, 3 Feb 2023 21:46:11 +0000 Subject: [PATCH 2/3] Include more structures --- tokio/src/sync/mutex.rs | 2 ++ tokio/src/sync/rwlock/owned_read_guard.rs | 1 + tokio/src/sync/rwlock/owned_write_guard.rs | 1 + tokio/src/sync/rwlock/owned_write_guard_mapped.rs | 1 + tokio/src/sync/rwlock/read_guard.rs | 1 + tokio/src/sync/rwlock/write_guard.rs | 1 + tokio/src/sync/rwlock/write_guard_mapped.rs | 1 + 7 files changed, 8 insertions(+) diff --git a/tokio/src/sync/mutex.rs b/tokio/src/sync/mutex.rs index f29257b177e..2243566509a 100644 --- a/tokio/src/sync/mutex.rs +++ b/tokio/src/sync/mutex.rs @@ -164,6 +164,7 @@ pub struct MutexGuard<'a, T: ?Sized> { /// point `lock` will succeed yet again. /// /// [`Arc`]: std::sync::Arc +#[clippy::has_significant_drop] pub struct OwnedMutexGuard { #[cfg(all(tokio_unstable, feature = "tracing"))] resource_span: tracing::Span, @@ -175,6 +176,7 @@ pub struct OwnedMutexGuard { /// This can be used to hold a subfield of the protected data. /// /// [`MutexGuard::map`]: method@MutexGuard::map +#[clippy::has_significant_drop] #[must_use = "if unused the Mutex will immediately unlock"] pub struct MappedMutexGuard<'a, T: ?Sized> { s: &'a semaphore::Semaphore, diff --git a/tokio/src/sync/rwlock/owned_read_guard.rs b/tokio/src/sync/rwlock/owned_read_guard.rs index 27b71bd988b..e457a1b663a 100644 --- a/tokio/src/sync/rwlock/owned_read_guard.rs +++ b/tokio/src/sync/rwlock/owned_read_guard.rs @@ -14,6 +14,7 @@ use std::sync::Arc; /// /// [`read_owned`]: method@crate::sync::RwLock::read_owned /// [`RwLock`]: struct@crate::sync::RwLock +#[clippy::has_significant_drop] pub struct OwnedRwLockReadGuard { #[cfg(all(tokio_unstable, feature = "tracing"))] pub(super) resource_span: tracing::Span, diff --git a/tokio/src/sync/rwlock/owned_write_guard.rs b/tokio/src/sync/rwlock/owned_write_guard.rs index dbedab4cbb2..0a8d7db6107 100644 --- a/tokio/src/sync/rwlock/owned_write_guard.rs +++ b/tokio/src/sync/rwlock/owned_write_guard.rs @@ -15,6 +15,7 @@ use std::sync::Arc; /// /// [`write_owned`]: method@crate::sync::RwLock::write_owned /// [`RwLock`]: struct@crate::sync::RwLock +#[clippy::has_significant_drop] pub struct OwnedRwLockWriteGuard { #[cfg(all(tokio_unstable, feature = "tracing"))] pub(super) resource_span: tracing::Span, diff --git a/tokio/src/sync/rwlock/owned_write_guard_mapped.rs b/tokio/src/sync/rwlock/owned_write_guard_mapped.rs index 55a24d96ac3..c986fd5eee8 100644 --- a/tokio/src/sync/rwlock/owned_write_guard_mapped.rs +++ b/tokio/src/sync/rwlock/owned_write_guard_mapped.rs @@ -14,6 +14,7 @@ use std::sync::Arc; /// /// [mapping]: method@crate::sync::OwnedRwLockWriteGuard::map /// [`OwnedRwLockWriteGuard`]: struct@crate::sync::OwnedRwLockWriteGuard +#[clippy::has_significant_drop] pub struct OwnedRwLockMappedWriteGuard { #[cfg(all(tokio_unstable, feature = "tracing"))] pub(super) resource_span: tracing::Span, diff --git a/tokio/src/sync/rwlock/read_guard.rs b/tokio/src/sync/rwlock/read_guard.rs index f5fc1d6de81..6f2eed1c864 100644 --- a/tokio/src/sync/rwlock/read_guard.rs +++ b/tokio/src/sync/rwlock/read_guard.rs @@ -12,6 +12,7 @@ use std::ops; /// /// [`read`]: method@crate::sync::RwLock::read /// [`RwLock`]: struct@crate::sync::RwLock +#[clippy::has_significant_drop] #[must_use = "if unused the RwLock will immediately unlock"] pub struct RwLockReadGuard<'a, T: ?Sized> { #[cfg(all(tokio_unstable, feature = "tracing"))] diff --git a/tokio/src/sync/rwlock/write_guard.rs b/tokio/src/sync/rwlock/write_guard.rs index cefa183d996..d584bb49c56 100644 --- a/tokio/src/sync/rwlock/write_guard.rs +++ b/tokio/src/sync/rwlock/write_guard.rs @@ -14,6 +14,7 @@ use std::ops; /// /// [`write`]: method@crate::sync::RwLock::write /// [`RwLock`]: struct@crate::sync::RwLock +#[clippy::has_significant_drop] #[must_use = "if unused the RwLock will immediately unlock"] pub struct RwLockWriteGuard<'a, T: ?Sized> { #[cfg(all(tokio_unstable, feature = "tracing"))] diff --git a/tokio/src/sync/rwlock/write_guard_mapped.rs b/tokio/src/sync/rwlock/write_guard_mapped.rs index b5c644a9e83..1f5d279111f 100644 --- a/tokio/src/sync/rwlock/write_guard_mapped.rs +++ b/tokio/src/sync/rwlock/write_guard_mapped.rs @@ -13,6 +13,7 @@ use std::ops; /// /// [mapping]: method@crate::sync::RwLockWriteGuard::map /// [`RwLockWriteGuard`]: struct@crate::sync::RwLockWriteGuard +#[clippy::has_significant_drop] pub struct RwLockMappedWriteGuard<'a, T: ?Sized> { #[cfg(all(tokio_unstable, feature = "tracing"))] pub(super) resource_span: tracing::Span, From 7869b6865f5730b218064c52ab3f6b4e70feeac1 Mon Sep 17 00:00:00 2001 From: Caio Date: Fri, 3 Feb 2023 21:53:02 +0000 Subject: [PATCH 3/3] Add yet more structures --- tokio/src/sync/semaphore.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tokio/src/sync/semaphore.rs b/tokio/src/sync/semaphore.rs index 6e5a1a88abb..1eee175088e 100644 --- a/tokio/src/sync/semaphore.rs +++ b/tokio/src/sync/semaphore.rs @@ -89,6 +89,7 @@ pub struct Semaphore { /// /// [`acquire`]: crate::sync::Semaphore::acquire() #[must_use] +#[clippy::has_significant_drop] #[derive(Debug)] pub struct SemaphorePermit<'a> { sem: &'a Semaphore, @@ -101,6 +102,7 @@ pub struct SemaphorePermit<'a> { /// /// [`acquire_owned`]: crate::sync::Semaphore::acquire_owned() #[must_use] +#[clippy::has_significant_drop] #[derive(Debug)] pub struct OwnedSemaphorePermit { sem: Arc,