Skip to content

Commit 53941be

Browse files
committed
Auto merge of #25744 - SimonSapin:cell-eq, r=alexcrichton
`core::cell::Cell<T>` and `core::cell::RefCell<T>` currently implement `PartialEq` when `T` does, and just defer to comparing `T` values. There is no reason the same shouldn’t apply to `Eq`. This enables `#[derive(Eq, PartialEq)]` on e.g. structs that have a `RefCell` field. r? @alexcrichton I’m unsure what to do with `#[stable]` attributes on `impl`s. `impl`s generated by `#[derive]` don’t have them.
2 parents efebe45 + bbf8ba7 commit 53941be

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libcore/cell.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
#![stable(feature = "rust1", since = "1.0.0")]
144144

145145
use clone::Clone;
146-
use cmp::PartialEq;
146+
use cmp::{PartialEq, Eq};
147147
use default::Default;
148148
use marker::{Copy, Send, Sync, Sized};
149149
use ops::{Deref, DerefMut, Drop};
@@ -263,6 +263,9 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
263263
}
264264
}
265265

266+
#[stable(feature = "cell_eq", since = "1.2.0")]
267+
impl<T:Eq + Copy> Eq for Cell<T> {}
268+
266269
/// A mutable memory location with dynamically checked borrow rules
267270
///
268271
/// See the [module-level documentation](index.html) for more.
@@ -273,7 +276,7 @@ pub struct RefCell<T: ?Sized> {
273276
}
274277

275278
/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
276-
#[derive(Copy, Clone, PartialEq, Debug)]
279+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
277280
#[unstable(feature = "std_misc")]
278281
pub enum BorrowState {
279282
/// The cell is currently being read, there is at least one active `borrow`.
@@ -479,6 +482,9 @@ impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
479482
}
480483
}
481484

485+
#[stable(feature = "cell_eq", since = "1.2.0")]
486+
impl<T: ?Sized + Eq> Eq for RefCell<T> {}
487+
482488
struct BorrowRef<'b> {
483489
_borrow: &'b Cell<BorrowFlag>,
484490
}

0 commit comments

Comments
 (0)