Rollup merge of #77055 - est31:more_track_caller, r=Mark-Simulacrum

Add #[track_caller] to more panicking Cell functions

Continuation of #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.
This commit is contained in:
Dylan DPC 2020-09-23 14:54:15 +02:00 committed by GitHub
commit c3c03f2f05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -697,6 +697,7 @@ impl<T> RefCell<T> {
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "refcell_replace", since = "1.24.0")] #[stable(feature = "refcell_replace", since = "1.24.0")]
#[track_caller]
pub fn replace(&self, t: T) -> T { pub fn replace(&self, t: T) -> T {
mem::replace(&mut *self.borrow_mut(), t) mem::replace(&mut *self.borrow_mut(), t)
} }
@ -719,6 +720,7 @@ impl<T> RefCell<T> {
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "refcell_replace_swap", since = "1.35.0")] #[stable(feature = "refcell_replace_swap", since = "1.35.0")]
#[track_caller]
pub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T { pub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T {
let mut_borrow = &mut *self.borrow_mut(); let mut_borrow = &mut *self.borrow_mut();
let replacement = f(mut_borrow); let replacement = f(mut_borrow);
@ -1052,6 +1054,7 @@ impl<T: Clone> Clone for RefCell<T> {
/// ///
/// Panics if the value is currently mutably borrowed. /// Panics if the value is currently mutably borrowed.
#[inline] #[inline]
#[track_caller]
fn clone(&self) -> RefCell<T> { fn clone(&self) -> RefCell<T> {
RefCell::new(self.borrow().clone()) RefCell::new(self.borrow().clone())
} }