Equality for references is implemented according to the docs, but in the following scenario (simplified from the original), the compiler seems to think it's not. Please help me understand why.
struct Node<T>(T);
pub struct Iter<'a, T: 'a> {
front_link: Option<&'a Node<T>>,
back_link: Option<&'a Node<T>>,
}
impl<'a, T> Iter<'a, T> {
fn next(&mut self) -> Option<&'a T> {
let done0 = self.front_link == self.back_link; // ERROR
self.front_link.take().map(|node_ref| {
let done1 = Some(node_ref) == self.back_link; // ERROR
let done2 = match (self.back_link) {
Some(nref) => {
//let i: u32 = node_ref; // Error shows that node_ref: &Node<T>
//let i: u32 = nref; // Error shows that nref: &Node<T>
nref == node_ref // ERROR
},
None => false
};
});
None
}
}
fn main() { }
The errors I get are
error: binary operation `==` cannot be applied to type `core::option::Option<&'a Node<T>>` [E0369]
let done0 = self.front_link == self.back_link;
^~~~~~~~~~~~~~~
error: binary operation `==` cannot be applied to type `core::option::Option<&Node<T>>` [E0369]
let done1 = Some(node_ref) == self.back_link;
^~~~~~~~~~~~~~
error: binary operation `==` cannot be applied to type `&Node<T>` [E0369]
nref == node_ref
^~~~