@@ -719,7 +719,7 @@ impl<T, const N: usize> Cell<[T; N]> {
719
719
#[ rustc_diagnostic_item = "RefCell" ]
720
720
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
721
721
pub struct RefCell < T : ?Sized > {
722
- borrow : Cell < BorrowFlag > ,
722
+ borrow : Cell < BorrowCounter > ,
723
723
// Stores the location of the earliest currently active borrow.
724
724
// This gets updated whenever we go from having zero borrows
725
725
// to having a single borrow. When a borrow occurs, this gets included
@@ -784,22 +784,22 @@ fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
784
784
//
785
785
// `Ref` and `RefMut` are both two words in size, and so there will likely never
786
786
// be enough `Ref`s or `RefMut`s in existence to overflow half of the `usize`
787
- // range. Thus, a `BorrowFlag ` will probably never overflow or underflow.
787
+ // range. Thus, a `BorrowCounter ` will probably never overflow or underflow.
788
788
// However, this is not a guarantee, as a pathological program could repeatedly
789
789
// create and then mem::forget `Ref`s or `RefMut`s. Thus, all code must
790
790
// explicitly check for overflow and underflow in order to avoid unsafety, or at
791
791
// least behave correctly in the event that overflow or underflow happens (e.g.,
792
792
// see BorrowRef::new).
793
- type BorrowFlag = isize ;
794
- const UNUSED : BorrowFlag = 0 ;
793
+ type BorrowCounter = isize ;
794
+ const UNUSED : BorrowCounter = 0 ;
795
795
796
796
#[ inline( always) ]
797
- fn is_writing ( x : BorrowFlag ) -> bool {
797
+ fn is_writing ( x : BorrowCounter ) -> bool {
798
798
x < UNUSED
799
799
}
800
800
801
801
#[ inline( always) ]
802
- fn is_reading ( x : BorrowFlag ) -> bool {
802
+ fn is_reading ( x : BorrowCounter ) -> bool {
803
803
x > UNUSED
804
804
}
805
805
@@ -1379,12 +1379,12 @@ impl<T> From<T> for RefCell<T> {
1379
1379
impl < T : CoerceUnsized < U > , U > CoerceUnsized < RefCell < U > > for RefCell < T > { }
1380
1380
1381
1381
struct BorrowRef < ' b > {
1382
- borrow : & ' b Cell < BorrowFlag > ,
1382
+ borrow : & ' b Cell < BorrowCounter > ,
1383
1383
}
1384
1384
1385
1385
impl < ' b > BorrowRef < ' b > {
1386
1386
#[ inline]
1387
- fn new ( borrow : & ' b Cell < BorrowFlag > ) -> Option < BorrowRef < ' b > > {
1387
+ fn new ( borrow : & ' b Cell < BorrowCounter > ) -> Option < BorrowRef < ' b > > {
1388
1388
let b = borrow. get ( ) . wrapping_add ( 1 ) ;
1389
1389
if !is_reading ( b) {
1390
1390
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
@@ -1425,7 +1425,7 @@ impl Clone for BorrowRef<'_> {
1425
1425
debug_assert ! ( is_reading( borrow) ) ;
1426
1426
// Prevent the borrow counter from overflowing into
1427
1427
// a writing borrow.
1428
- assert ! ( borrow != BorrowFlag :: MAX ) ;
1428
+ assert ! ( borrow != BorrowCounter :: MAX ) ;
1429
1429
self . borrow . set ( borrow + 1 ) ;
1430
1430
BorrowRef { borrow : self . borrow }
1431
1431
}
@@ -1773,7 +1773,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
1773
1773
}
1774
1774
1775
1775
struct BorrowRefMut < ' b > {
1776
- borrow : & ' b Cell < BorrowFlag > ,
1776
+ borrow : & ' b Cell < BorrowCounter > ,
1777
1777
}
1778
1778
1779
1779
impl Drop for BorrowRefMut < ' _ > {
@@ -1787,7 +1787,7 @@ impl Drop for BorrowRefMut<'_> {
1787
1787
1788
1788
impl < ' b > BorrowRefMut < ' b > {
1789
1789
#[ inline]
1790
- fn new ( borrow : & ' b Cell < BorrowFlag > ) -> Option < BorrowRefMut < ' b > > {
1790
+ fn new ( borrow : & ' b Cell < BorrowCounter > ) -> Option < BorrowRefMut < ' b > > {
1791
1791
// NOTE: Unlike BorrowRefMut::clone, new is called to create the initial
1792
1792
// mutable reference, and so there must currently be no existing
1793
1793
// references. Thus, while clone increments the mutable refcount, here
@@ -1811,7 +1811,7 @@ impl<'b> BorrowRefMut<'b> {
1811
1811
let borrow = self . borrow . get ( ) ;
1812
1812
debug_assert ! ( is_writing( borrow) ) ;
1813
1813
// Prevent the borrow counter from underflowing.
1814
- assert ! ( borrow != BorrowFlag :: MIN ) ;
1814
+ assert ! ( borrow != BorrowCounter :: MIN ) ;
1815
1815
self . borrow . set ( borrow - 1 ) ;
1816
1816
BorrowRefMut { borrow : self . borrow }
1817
1817
}
0 commit comments