Skip to content

Rollup of 11 pull requests #142604

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

Closed
wants to merge 29 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1e10dfc
Add all rustc_std_internal_symbol to symbols.o
bjorn3 May 8, 2025
2d2d70f
Remove dependency injection for the panic runtime
bjorn3 May 8, 2025
3a7ae67
Stop handling explicit dependencies on the panic runtime
bjorn3 May 8, 2025
f8d1bfa
Avoid exporting panic_unwind as stdlib cargo feature
bjorn3 May 8, 2025
6df5456
Make comment on activate_injected_dep a doc comment
bjorn3 May 9, 2025
0e1db54
Windows: Use anonymous pipes in Command
ChrisDenton Jun 14, 2025
3cb0cba
Handle win32 separator & prefixes for cygwin paths
Berrysoft Jun 1, 2025
32c0cb0
Add union with default field values case test
jieyouxu Jun 16, 2025
718df66
Two changes: Have BorrowError & BorrowMutError derive Debug and add
nealsid Jun 14, 2025
2fca05a
Rename BorrowFlag type to BorrowCounter
nealsid Jun 14, 2025
23e35c6
Add support for repetition to `proc_macro::quote`
moatom May 26, 2025
7cfc51b
Update books
rustbot Jun 16, 2025
8a7b50a
Fold unnecessary visit_struct_field_def in AstValidator
compiler-errors Jun 16, 2025
994794a
Handle same-crate macro for borrowck semicolon suggestion
Urgau Jun 16, 2025
7b29a5d
Revert overeager warning for misuse of `--print native-static-libs`
workingjubilee Jun 16, 2025
7859a37
explicitly set llvm_abiname option on existing ppc64 targets
ostylk Jun 11, 2025
9c1180b
indicate ppc64 elf abi in e_flags
ostylk Jun 11, 2025
2dd9cc1
Reject union default field values
jieyouxu Jun 16, 2025
3b9ae23
Rollup merge of #140809 - bjorn3:panic_runtime_cleanup, r=wesleywiser…
jhpratt Jun 17, 2025
e698e9c
Rollup merge of #141608 - moatom:proc_macro-140238, r=dtolnay
jhpratt Jun 17, 2025
39a0bdc
Rollup merge of #141864 - Berrysoft:cygwin-path, r=ChrisDenton
jhpratt Jun 17, 2025
ad7c50f
Rollup merge of #142216 - nealsid:refcell-logging, r=tgross35
jhpratt Jun 17, 2025
9b267ea
Rollup merge of #142517 - ChrisDenton:anon-pipe, r=Mark-Simulacrum
jhpratt Jun 17, 2025
78e2974
Rollup merge of #142570 - jieyouxu:disunion, r=estebank
jhpratt Jun 17, 2025
70320e7
Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease
jhpratt Jun 17, 2025
7423763
Rollup merge of #142585 - rustbot:docs-update, r=ehuss
jhpratt Jun 17, 2025
ccd9b6a
Rollup merge of #142586 - compiler-errors:remove-visit-struct-field-d…
jhpratt Jun 17, 2025
0f50901
Rollup merge of #142595 - workingjubilee:revert-warning-138139, r=Chr…
jhpratt Jun 17, 2025
5d62529
Rollup merge of #142598 - ostylk:fix/ppc64_llvmabi, r=nikic,workingju…
jhpratt Jun 17, 2025
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
66 changes: 30 additions & 36 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ impl<T, const N: usize> Cell<[T; N]> {
#[rustc_diagnostic_item = "RefCell"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RefCell<T: ?Sized> {
borrow: Cell<BorrowFlag>,
borrow: Cell<BorrowCounter>,
// Stores the location of the earliest currently active borrow.
// This gets updated whenever we go from having zero borrows
// to having a single borrow. When a borrow occurs, this gets included
Expand All @@ -732,54 +732,48 @@ pub struct RefCell<T: ?Sized> {
/// An error returned by [`RefCell::try_borrow`].
#[stable(feature = "try_borrow", since = "1.13.0")]
#[non_exhaustive]
#[derive(Debug)]
pub struct BorrowError {
#[cfg(feature = "debug_refcell")]
location: &'static crate::panic::Location<'static>,
}

#[stable(feature = "try_borrow", since = "1.13.0")]
impl Debug for BorrowError {
impl Display for BorrowError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut builder = f.debug_struct("BorrowError");

#[cfg(feature = "debug_refcell")]
builder.field("location", self.location);
let res = write!(
f,
"RefCell already mutably borrowed; a previous borrow was at {}",
self.location
);

builder.finish()
}
}
#[cfg(not(feature = "debug_refcell"))]
let res = Display::fmt("RefCell already mutably borrowed", f);

#[stable(feature = "try_borrow", since = "1.13.0")]
impl Display for BorrowError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt("already mutably borrowed", f)
res
}
}

/// An error returned by [`RefCell::try_borrow_mut`].
#[stable(feature = "try_borrow", since = "1.13.0")]
#[non_exhaustive]
#[derive(Debug)]
pub struct BorrowMutError {
#[cfg(feature = "debug_refcell")]
location: &'static crate::panic::Location<'static>,
}

#[stable(feature = "try_borrow", since = "1.13.0")]
impl Debug for BorrowMutError {
impl Display for BorrowMutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut builder = f.debug_struct("BorrowMutError");

#[cfg(feature = "debug_refcell")]
builder.field("location", self.location);
let res = write!(f, "RefCell already borrowed; a previous borrow was at {}", self.location);

builder.finish()
}
}
#[cfg(not(feature = "debug_refcell"))]
let res = Display::fmt("RefCell already borrowed", f);

#[stable(feature = "try_borrow", since = "1.13.0")]
impl Display for BorrowMutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt("already borrowed", f)
res
}
}

Expand All @@ -788,15 +782,15 @@ impl Display for BorrowMutError {
#[track_caller]
#[cold]
fn panic_already_borrowed(err: BorrowMutError) -> ! {
panic!("already borrowed: {:?}", err)
panic!("{err}")
}

// 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)
panic!("{err}")
}

// Positive values represent the number of `Ref` active. Negative values
Expand All @@ -806,22 +800,22 @@ fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
//
// `Ref` and `RefMut` are both two words in size, and so there will likely never
// be enough `Ref`s or `RefMut`s in existence to overflow half of the `usize`
// range. Thus, a `BorrowFlag` will probably never overflow or underflow.
// range. Thus, a `BorrowCounter` will probably never overflow or underflow.
// However, this is not a guarantee, as a pathological program could repeatedly
// create and then mem::forget `Ref`s or `RefMut`s. Thus, all code must
// explicitly check for overflow and underflow in order to avoid unsafety, or at
// least behave correctly in the event that overflow or underflow happens (e.g.,
// see BorrowRef::new).
type BorrowFlag = isize;
const UNUSED: BorrowFlag = 0;
type BorrowCounter = isize;
const UNUSED: BorrowCounter = 0;

#[inline(always)]
fn is_writing(x: BorrowFlag) -> bool {
fn is_writing(x: BorrowCounter) -> bool {
x < UNUSED
}

#[inline(always)]
fn is_reading(x: BorrowFlag) -> bool {
fn is_reading(x: BorrowCounter) -> bool {
x > UNUSED
}

Expand Down Expand Up @@ -1401,12 +1395,12 @@ impl<T> From<T> for RefCell<T> {
impl<T: CoerceUnsized<U>, U> CoerceUnsized<RefCell<U>> for RefCell<T> {}

struct BorrowRef<'b> {
borrow: &'b Cell<BorrowFlag>,
borrow: &'b Cell<BorrowCounter>,
}

impl<'b> BorrowRef<'b> {
#[inline]
fn new(borrow: &'b Cell<BorrowFlag>) -> Option<BorrowRef<'b>> {
fn new(borrow: &'b Cell<BorrowCounter>) -> Option<BorrowRef<'b>> {
let b = borrow.get().wrapping_add(1);
if !is_reading(b) {
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
Expand Down Expand Up @@ -1447,7 +1441,7 @@ impl Clone for BorrowRef<'_> {
debug_assert!(is_reading(borrow));
// Prevent the borrow counter from overflowing into
// a writing borrow.
assert!(borrow != BorrowFlag::MAX);
assert!(borrow != BorrowCounter::MAX);
self.borrow.set(borrow + 1);
BorrowRef { borrow: self.borrow }
}
Expand Down Expand Up @@ -1795,7 +1789,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
}

struct BorrowRefMut<'b> {
borrow: &'b Cell<BorrowFlag>,
borrow: &'b Cell<BorrowCounter>,
}

impl Drop for BorrowRefMut<'_> {
Expand All @@ -1809,7 +1803,7 @@ impl Drop for BorrowRefMut<'_> {

impl<'b> BorrowRefMut<'b> {
#[inline]
fn new(borrow: &'b Cell<BorrowFlag>) -> Option<BorrowRefMut<'b>> {
fn new(borrow: &'b Cell<BorrowCounter>) -> Option<BorrowRefMut<'b>> {
// NOTE: Unlike BorrowRefMut::clone, new is called to create the initial
// mutable reference, and so there must currently be no existing
// references. Thus, while clone increments the mutable refcount, here
Expand All @@ -1833,7 +1827,7 @@ impl<'b> BorrowRefMut<'b> {
let borrow = self.borrow.get();
debug_assert!(is_writing(borrow));
// Prevent the borrow counter from underflowing.
assert!(borrow != BorrowFlag::MIN);
assert!(borrow != BorrowCounter::MIN);
self.borrow.set(borrow - 1);
BorrowRefMut { borrow: self.borrow }
}
Expand Down