Skip to content

Commit

Permalink
Rollup merge of rust-lang#103845 - camsteffen:data-structures-track-c…
Browse files Browse the repository at this point in the history
…aller, r=compiler-errors

Add track_caller to some Lock methods

Would have helped to diagnose rust-lang#103844.
  • Loading branch information
Dylan-DPC authored Nov 3, 2022
2 parents 44e0b72 + 10a5e75 commit 16f0c59
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ impl<T> Lock<T> {

#[cfg(parallel_compiler)]
#[inline(always)]
#[track_caller]
pub fn lock(&self) -> LockGuard<'_, T> {
if ERROR_CHECKING {
self.0.try_lock().expect("lock was already held")
Expand All @@ -420,21 +421,25 @@ impl<T> Lock<T> {

#[cfg(not(parallel_compiler))]
#[inline(always)]
#[track_caller]
pub fn lock(&self) -> LockGuard<'_, T> {
self.0.borrow_mut()
}

#[inline(always)]
#[track_caller]
pub fn with_lock<F: FnOnce(&mut T) -> R, R>(&self, f: F) -> R {
f(&mut *self.lock())
}

#[inline(always)]
#[track_caller]
pub fn borrow(&self) -> LockGuard<'_, T> {
self.lock()
}

#[inline(always)]
#[track_caller]
pub fn borrow_mut(&self) -> LockGuard<'_, T> {
self.lock()
}
Expand Down Expand Up @@ -476,6 +481,7 @@ impl<T> RwLock<T> {

#[cfg(not(parallel_compiler))]
#[inline(always)]
#[track_caller]
pub fn read(&self) -> ReadGuard<'_, T> {
self.0.borrow()
}
Expand All @@ -491,6 +497,7 @@ impl<T> RwLock<T> {
}

#[inline(always)]
#[track_caller]
pub fn with_read_lock<F: FnOnce(&T) -> R, R>(&self, f: F) -> R {
f(&*self.read())
}
Expand All @@ -509,6 +516,7 @@ impl<T> RwLock<T> {

#[cfg(not(parallel_compiler))]
#[inline(always)]
#[track_caller]
pub fn write(&self) -> WriteGuard<'_, T> {
self.0.borrow_mut()
}
Expand All @@ -524,16 +532,19 @@ impl<T> RwLock<T> {
}

#[inline(always)]
#[track_caller]
pub fn with_write_lock<F: FnOnce(&mut T) -> R, R>(&self, f: F) -> R {
f(&mut *self.write())
}

#[inline(always)]
#[track_caller]
pub fn borrow(&self) -> ReadGuard<'_, T> {
self.read()
}

#[inline(always)]
#[track_caller]
pub fn borrow_mut(&self) -> WriteGuard<'_, T> {
self.write()
}
Expand Down

0 comments on commit 16f0c59

Please sign in to comment.