Skip to content

Commit

Permalink
docs: document panics / track_caller
Browse files Browse the repository at this point in the history
Document merging permits from distinct Semaphore instances causes a
panic, and add #[track_caller] annotation.
  • Loading branch information
domodwyer committed Aug 31, 2022
1 parent 8356f05 commit 5900f84
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tokio/src/sync/semaphore.rs
Expand Up @@ -625,6 +625,12 @@ impl<'a> SemaphorePermit<'a> {
/// without releasing the permits it holds.
///
/// Permits held by both `self` and `other` are released when `self` drops.
///
/// # Panics
///
/// This function panics if permits from different [`Semaphore`] instances
/// are merged.
#[track_caller]
pub fn merge(&mut self, mut other: Self) {
assert!(
std::ptr::eq(self.sem, other.sem),
Expand All @@ -647,6 +653,12 @@ impl OwnedSemaphorePermit {
/// without releasing the permits it holds.
///
/// Permits held by both `self` and `other` are released when `self` drops.
///
/// # Panics
///
/// This function panics if permits from different [`Semaphore`] instances
/// are merged.
#[track_caller]
pub fn merge(&mut self, mut other: Self) {
assert!(
Arc::ptr_eq(&self.sem, &other.sem),
Expand Down

0 comments on commit 5900f84

Please sign in to comment.