From bbf8ba7c2351caba1b585346e5709f8eb476f169 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sun, 24 May 2015 10:38:59 +0200 Subject: [PATCH] Implement Eq for Cell and RefCell. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `core::cell::Cell` and `core::cell::RefCell` 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. --- src/libcore/cell.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 45a80122104..8f531de2611 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -143,7 +143,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use clone::Clone; -use cmp::PartialEq; +use cmp::{PartialEq, Eq}; use default::Default; use marker::{Copy, Send, Sync, Sized}; use ops::{Deref, DerefMut, Drop}; @@ -263,6 +263,9 @@ impl PartialEq for Cell { } } +#[stable(feature = "cell_eq", since = "1.2.0")] +impl Eq for Cell {} + /// A mutable memory location with dynamically checked borrow rules /// /// See the [module-level documentation](index.html) for more. @@ -273,7 +276,7 @@ pub struct RefCell { } /// An enumeration of values returned from the `state` method on a `RefCell`. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[unstable(feature = "std_misc")] pub enum BorrowState { /// The cell is currently being read, there is at least one active `borrow`. @@ -479,6 +482,9 @@ impl PartialEq for RefCell { } } +#[stable(feature = "cell_eq", since = "1.2.0")] +impl Eq for RefCell {} + struct BorrowRef<'b> { _borrow: &'b Cell, }