Skip to content

Commit 2160e83

Browse files
committed
Have BorrowError & BorrowMutError derive Debug rather than implement Debug themselves
The implementation does not print anything differently from what the derived implementation does, so we don't need it.
1 parent c359117 commit 2160e83

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

library/core/src/cell.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -732,21 +732,10 @@ pub struct RefCell<T: ?Sized> {
732732
/// An error returned by [`RefCell::try_borrow`].
733733
#[stable(feature = "try_borrow", since = "1.13.0")]
734734
#[non_exhaustive]
735+
#[derive(Debug)]
735736
pub struct BorrowError {
736737
#[cfg(feature = "debug_refcell")]
737-
location: &'static crate::panic::Location<'static>,
738-
}
739-
740-
#[stable(feature = "try_borrow", since = "1.13.0")]
741-
impl Debug for BorrowError {
742-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
743-
let mut builder = f.debug_struct("BorrowError");
744-
745-
#[cfg(feature = "debug_refcell")]
746-
builder.field("location", self.location);
747-
748-
builder.finish()
749-
}
738+
_location: &'static crate::panic::Location<'static>,
750739
}
751740

752741
#[stable(feature = "try_borrow", since = "1.13.0")]
@@ -759,21 +748,10 @@ impl Display for BorrowError {
759748
/// An error returned by [`RefCell::try_borrow_mut`].
760749
#[stable(feature = "try_borrow", since = "1.13.0")]
761750
#[non_exhaustive]
751+
#[derive(Debug)]
762752
pub struct BorrowMutError {
763753
#[cfg(feature = "debug_refcell")]
764-
location: &'static crate::panic::Location<'static>,
765-
}
766-
767-
#[stable(feature = "try_borrow", since = "1.13.0")]
768-
impl Debug for BorrowMutError {
769-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
770-
let mut builder = f.debug_struct("BorrowMutError");
771-
772-
#[cfg(feature = "debug_refcell")]
773-
builder.field("location", self.location);
774-
775-
builder.finish()
776-
}
754+
_location: &'static crate::panic::Location<'static>,
777755
}
778756

779757
#[stable(feature = "try_borrow", since = "1.13.0")]
@@ -1036,7 +1014,7 @@ impl<T: ?Sized> RefCell<T> {
10361014
// If a borrow occurred, then we must already have an outstanding borrow,
10371015
// so `borrowed_at` will be `Some`
10381016
#[cfg(feature = "debug_refcell")]
1039-
location: self.borrowed_at.get().unwrap(),
1017+
_location: self.borrowed_at.get().unwrap(),
10401018
}),
10411019
}
10421020
}
@@ -1125,7 +1103,7 @@ impl<T: ?Sized> RefCell<T> {
11251103
// If a borrow occurred, then we must already have an outstanding borrow,
11261104
// so `borrowed_at` will be `Some`
11271105
#[cfg(feature = "debug_refcell")]
1128-
location: self.borrowed_at.get().unwrap(),
1106+
_location: self.borrowed_at.get().unwrap(),
11291107
}),
11301108
}
11311109
}
@@ -1255,7 +1233,7 @@ impl<T: ?Sized> RefCell<T> {
12551233
// If a borrow occurred, then we must already have an outstanding borrow,
12561234
// so `borrowed_at` will be `Some`
12571235
#[cfg(feature = "debug_refcell")]
1258-
location: self.borrowed_at.get().unwrap(),
1236+
_location: self.borrowed_at.get().unwrap(),
12591237
})
12601238
}
12611239
}

0 commit comments

Comments
 (0)