@@ -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
@@ -800,22 +800,22 @@ fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
800
800
//
801
801
// `Ref` and `RefMut` are both two words in size, and so there will likely never
802
802
// be enough `Ref`s or `RefMut`s in existence to overflow half of the `usize`
803
- // range. Thus, a `BorrowFlag ` will probably never overflow or underflow.
803
+ // range. Thus, a `BorrowCounter ` will probably never overflow or underflow.
804
804
// However, this is not a guarantee, as a pathological program could repeatedly
805
805
// create and then mem::forget `Ref`s or `RefMut`s. Thus, all code must
806
806
// explicitly check for overflow and underflow in order to avoid unsafety, or at
807
807
// least behave correctly in the event that overflow or underflow happens (e.g.,
808
808
// see BorrowRef::new).
809
- type BorrowFlag = isize ;
810
- const UNUSED : BorrowFlag = 0 ;
809
+ type BorrowCounter = isize ;
810
+ const UNUSED : BorrowCounter = 0 ;
811
811
812
812
#[ inline( always) ]
813
- fn is_writing ( x : BorrowFlag ) -> bool {
813
+ fn is_writing ( x : BorrowCounter ) -> bool {
814
814
x < UNUSED
815
815
}
816
816
817
817
#[ inline( always) ]
818
- fn is_reading ( x : BorrowFlag ) -> bool {
818
+ fn is_reading ( x : BorrowCounter ) -> bool {
819
819
x > UNUSED
820
820
}
821
821
@@ -1395,12 +1395,12 @@ impl<T> From<T> for RefCell<T> {
1395
1395
impl < T : CoerceUnsized < U > , U > CoerceUnsized < RefCell < U > > for RefCell < T > { }
1396
1396
1397
1397
struct BorrowRef < ' b > {
1398
- borrow : & ' b Cell < BorrowFlag > ,
1398
+ borrow : & ' b Cell < BorrowCounter > ,
1399
1399
}
1400
1400
1401
1401
impl < ' b > BorrowRef < ' b > {
1402
1402
#[ inline]
1403
- fn new ( borrow : & ' b Cell < BorrowFlag > ) -> Option < BorrowRef < ' b > > {
1403
+ fn new ( borrow : & ' b Cell < BorrowCounter > ) -> Option < BorrowRef < ' b > > {
1404
1404
let b = borrow. get ( ) . wrapping_add ( 1 ) ;
1405
1405
if !is_reading ( b) {
1406
1406
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
@@ -1441,7 +1441,7 @@ impl Clone for BorrowRef<'_> {
1441
1441
debug_assert ! ( is_reading( borrow) ) ;
1442
1442
// Prevent the borrow counter from overflowing into
1443
1443
// a writing borrow.
1444
- assert ! ( borrow != BorrowFlag :: MAX ) ;
1444
+ assert ! ( borrow != BorrowCounter :: MAX ) ;
1445
1445
self . borrow . set ( borrow + 1 ) ;
1446
1446
BorrowRef { borrow : self . borrow }
1447
1447
}
@@ -1789,7 +1789,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
1789
1789
}
1790
1790
1791
1791
struct BorrowRefMut < ' b > {
1792
- borrow : & ' b Cell < BorrowFlag > ,
1792
+ borrow : & ' b Cell < BorrowCounter > ,
1793
1793
}
1794
1794
1795
1795
impl Drop for BorrowRefMut < ' _ > {
@@ -1803,7 +1803,7 @@ impl Drop for BorrowRefMut<'_> {
1803
1803
1804
1804
impl < ' b > BorrowRefMut < ' b > {
1805
1805
#[ inline]
1806
- fn new ( borrow : & ' b Cell < BorrowFlag > ) -> Option < BorrowRefMut < ' b > > {
1806
+ fn new ( borrow : & ' b Cell < BorrowCounter > ) -> Option < BorrowRefMut < ' b > > {
1807
1807
// NOTE: Unlike BorrowRefMut::clone, new is called to create the initial
1808
1808
// mutable reference, and so there must currently be no existing
1809
1809
// references. Thus, while clone increments the mutable refcount, here
@@ -1827,7 +1827,7 @@ impl<'b> BorrowRefMut<'b> {
1827
1827
let borrow = self . borrow . get ( ) ;
1828
1828
debug_assert ! ( is_writing( borrow) ) ;
1829
1829
// Prevent the borrow counter from underflowing.
1830
- assert ! ( borrow != BorrowFlag :: MIN ) ;
1830
+ assert ! ( borrow != BorrowCounter :: MIN ) ;
1831
1831
self . borrow . set ( borrow - 1 ) ;
1832
1832
BorrowRefMut { borrow : self . borrow }
1833
1833
}
0 commit comments