Skip to content

Minor tweaks to refcell logging #142216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ impl Debug for BorrowError {
let mut builder = f.debug_struct("BorrowError");

#[cfg(feature = "debug_refcell")]
builder.field("location", self.location);
builder.field("location", &format_args!("{}", self.location));

builder.finish()
}
Expand All @@ -770,7 +770,7 @@ impl Debug for BorrowMutError {
let mut builder = f.debug_struct("BorrowMutError");

#[cfg(feature = "debug_refcell")]
builder.field("location", self.location);
builder.field("location", &format_args!("{}", self.location));

builder.finish()
}
Expand All @@ -787,16 +787,24 @@ impl Display for BorrowMutError {
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[track_caller]
#[cold]
fn panic_already_borrowed(err: BorrowMutError) -> ! {
panic!("already borrowed: {:?}", err)
fn panic_already_borrowed(_err: BorrowMutError) -> ! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit, this can be _err -> err since it is used

if cfg!(feature = "debug_refcell") {
panic!("cannot borrow as mutable because it is also borrowed as immutable here {:?}", _err);
} else {
panic!("cannot borrow as mutable because it is also borrowed as immutable");
}
}

// This ensures the panicking code is outlined from `borrow` for `RefCell`.
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[track_caller]
#[cold]
fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
panic!("already mutably borrowed: {:?}", err)
fn panic_already_mutably_borrowed(_err: BorrowError) -> ! {
if cfg!(feature = "debug_refcell") {
panic!("cannot borrow as immutable because it is also borrowed as mutable here {:?}", _err);
} else {
panic!("cannot borrow as immutable because it is also borrowed as mutable");
}
}

// Positive values represent the number of `Ref` active. Negative values
Expand Down
Loading