Skip to content

Commit

Permalink
Rollup merge of rust-lang#77055 - est31:more_track_caller, r=Mark-Sim…
Browse files Browse the repository at this point in the history
…ulacrum

Add #[track_caller] to more panicking Cell functions

Continuation of rust-lang#74526

Adds the #[track_caller] attribute to almost all panicking Cell
functions. The ones that borrow two Cells in their function
body are spared, because the panic location helps pinpoint
which of the two borrows failed. You'd need to have
full debuginfo and backtraces enabled together with column
info in order to be able to discern the cases.
Column info in debuginfo is only available on non-Windows platforms.
  • Loading branch information
ecstatic-morse committed Sep 22, 2020
2 parents 51ba922 + 05c3a2b commit 1d603db
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ impl<T> RefCell<T> {
/// ```
#[inline]
#[stable(feature = "refcell_replace", since = "1.24.0")]
#[track_caller]
pub fn replace(&self, t: T) -> T {
mem::replace(&mut *self.borrow_mut(), t)
}
Expand All @@ -719,6 +720,7 @@ impl<T> RefCell<T> {
/// ```
#[inline]
#[stable(feature = "refcell_replace_swap", since = "1.35.0")]
#[track_caller]
pub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T {
let mut_borrow = &mut *self.borrow_mut();
let replacement = f(mut_borrow);
Expand Down Expand Up @@ -1052,6 +1054,7 @@ impl<T: Clone> Clone for RefCell<T> {
///
/// Panics if the value is currently mutably borrowed.
#[inline]
#[track_caller]
fn clone(&self) -> RefCell<T> {
RefCell::new(self.borrow().clone())
}
Expand Down

0 comments on commit 1d603db

Please sign in to comment.