]> git.lizzy.rs Git - rust.git/blob - src/libcore/cmp.rs
core: Split apart the global `core` feature
[rust.git] / src / libcore / cmp.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Functionality for ordering and comparison.
12 //!
13 //! This module defines both `PartialOrd` and `PartialEq` traits which are used
14 //! by the compiler to implement comparison operators. Rust programs may
15 //! implement `PartialOrd` to overload the `<`, `<=`, `>`, and `>=` operators,
16 //! and may implement `PartialEq` to overload the `==` and `!=` operators.
17
18 #![stable(feature = "rust1", since = "1.0.0")]
19
20 use self::Ordering::*;
21
22 use marker::Sized;
23 use option::Option::{self, Some, None};
24
25 /// Trait for equality comparisons which are [partial equivalence
26 /// relations](http://en.wikipedia.org/wiki/Partial_equivalence_relation).
27 ///
28 /// This trait allows for partial equality, for types that do not have a full
29 /// equivalence relation.  For example, in floating point numbers `NaN != NaN`,
30 /// so floating point types implement `PartialEq` but not `Eq`.
31 ///
32 /// Formally, the equality must be (for all `a`, `b` and `c`):
33 ///
34 /// - symmetric: `a == b` implies `b == a`; and
35 /// - transitive: `a == b` and `b == c` implies `a == c`.
36 ///
37 /// Note that these requirements mean that the trait itself must be implemented
38 /// symmetrically and transitively: if `T: PartialEq<U>` and `U: PartialEq<V>`
39 /// then `U: PartialEq<T>` and `T: PartialEq<V>`.
40 ///
41 /// PartialEq only requires the `eq` method to be implemented; `ne` is defined
42 /// in terms of it by default. Any manual implementation of `ne` *must* respect
43 /// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
44 /// only if `a != b`.
45 #[lang = "eq"]
46 #[stable(feature = "rust1", since = "1.0.0")]
47 pub trait PartialEq<Rhs: ?Sized = Self> {
48     /// This method tests for `self` and `other` values to be equal, and is used
49     /// by `==`.
50     #[stable(feature = "rust1", since = "1.0.0")]
51     fn eq(&self, other: &Rhs) -> bool;
52
53     /// This method tests for `!=`.
54     #[inline]
55     #[stable(feature = "rust1", since = "1.0.0")]
56     fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
57 }
58
59 /// Trait for equality comparisons which are [equivalence relations](
60 /// https://en.wikipedia.org/wiki/Equivalence_relation).
61 ///
62 /// This means, that in addition to `a == b` and `a != b` being strict inverses, the equality must
63 /// be (for all `a`, `b` and `c`):
64 ///
65 /// - reflexive: `a == a`;
66 /// - symmetric: `a == b` implies `b == a`; and
67 /// - transitive: `a == b` and `b == c` implies `a == c`.
68 ///
69 /// This property cannot be checked by the compiler, and therefore `Eq` implies
70 /// `PartialEq`, and has no extra methods.
71 #[stable(feature = "rust1", since = "1.0.0")]
72 pub trait Eq: PartialEq<Self> {
73     // FIXME #13101: this method is used solely by #[deriving] to
74     // assert that every component of a type implements #[deriving]
75     // itself, the current deriving infrastructure means doing this
76     // assertion without using a method on this trait is nearly
77     // impossible.
78     //
79     // This should never be implemented by hand.
80     #[doc(hidden)]
81     #[inline(always)]
82     #[stable(feature = "rust1", since = "1.0.0")]
83     fn assert_receiver_is_total_eq(&self) {}
84 }
85
86 /// An `Ordering` is the result of a comparison between two values.
87 ///
88 /// # Examples
89 ///
90 /// ```
91 /// use std::cmp::Ordering;
92 ///
93 /// let result = 1.cmp(&2);
94 /// assert_eq!(Ordering::Less, result);
95 ///
96 /// let result = 1.cmp(&1);
97 /// assert_eq!(Ordering::Equal, result);
98 ///
99 /// let result = 2.cmp(&1);
100 /// assert_eq!(Ordering::Greater, result);
101 /// ```
102 #[derive(Clone, Copy, PartialEq, Debug)]
103 #[stable(feature = "rust1", since = "1.0.0")]
104 pub enum Ordering {
105     /// An ordering where a compared value is less [than another].
106     #[stable(feature = "rust1", since = "1.0.0")]
107     Less = -1,
108     /// An ordering where a compared value is equal [to another].
109     #[stable(feature = "rust1", since = "1.0.0")]
110     Equal = 0,
111     /// An ordering where a compared value is greater [than another].
112     #[stable(feature = "rust1", since = "1.0.0")]
113     Greater = 1,
114 }
115
116 impl Ordering {
117     /// Reverse the `Ordering`.
118     ///
119     /// * `Less` becomes `Greater`.
120     /// * `Greater` becomes `Less`.
121     /// * `Equal` becomes `Equal`.
122     ///
123     /// # Examples
124     ///
125     /// Basic behavior:
126     ///
127     /// ```
128     /// use std::cmp::Ordering;
129     ///
130     /// assert_eq!(Ordering::Less.reverse(), Ordering::Greater);
131     /// assert_eq!(Ordering::Equal.reverse(), Ordering::Equal);
132     /// assert_eq!(Ordering::Greater.reverse(), Ordering::Less);
133     /// ```
134     ///
135     /// This method can be used to reverse a comparison:
136     ///
137     /// ```
138     /// use std::cmp::Ordering;
139     ///
140     /// let mut data: &mut [_] = &mut [2, 10, 5, 8];
141     ///
142     /// // sort the array from largest to smallest.
143     /// data.sort_by(|a, b| a.cmp(b).reverse());
144     ///
145     /// let b: &mut [_] = &mut [10, 8, 5, 2];
146     /// assert!(data == b);
147     /// ```
148     #[inline]
149     #[stable(feature = "rust1", since = "1.0.0")]
150     pub fn reverse(self) -> Ordering {
151         unsafe {
152             // this compiles really nicely (to a single instruction);
153             // an explicit match has a pile of branches and
154             // comparisons.
155             //
156             // NB. it is safe because of the explicit discriminants
157             // given above.
158             ::mem::transmute::<_, Ordering>(-(self as i8))
159         }
160     }
161 }
162
163 /// Trait for types that form a [total order](https://en.wikipedia.org/wiki/Total_order).
164 ///
165 /// An order is a total order if it is (for all `a`, `b` and `c`):
166 ///
167 /// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and
168 /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
169 #[stable(feature = "rust1", since = "1.0.0")]
170 pub trait Ord: Eq + PartialOrd<Self> {
171     /// This method returns an `Ordering` between `self` and `other`.
172     ///
173     /// By convention, `self.cmp(&other)` returns the ordering matching the expression
174     /// `self <operator> other` if true.
175     ///
176     /// # Examples
177     ///
178     /// ```
179     /// use std::cmp::Ordering;
180     ///
181     /// assert_eq!(5.cmp(&10), Ordering::Less);
182     /// assert_eq!(10.cmp(&5), Ordering::Greater);
183     /// assert_eq!(5.cmp(&5), Ordering::Equal);
184     /// ```
185     #[stable(feature = "rust1", since = "1.0.0")]
186     fn cmp(&self, other: &Self) -> Ordering;
187 }
188
189 #[stable(feature = "rust1", since = "1.0.0")]
190 impl Eq for Ordering {}
191
192 #[stable(feature = "rust1", since = "1.0.0")]
193 impl Ord for Ordering {
194     #[inline]
195     #[stable(feature = "rust1", since = "1.0.0")]
196     fn cmp(&self, other: &Ordering) -> Ordering {
197         (*self as i32).cmp(&(*other as i32))
198     }
199 }
200
201 #[stable(feature = "rust1", since = "1.0.0")]
202 impl PartialOrd for Ordering {
203     #[inline]
204     #[stable(feature = "rust1", since = "1.0.0")]
205     fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {
206         (*self as i32).partial_cmp(&(*other as i32))
207     }
208 }
209
210 /// Trait for values that can be compared for a sort-order.
211 ///
212 /// The comparison must satisfy, for all `a`, `b` and `c`:
213 ///
214 /// - antisymmetry: if `a < b` then `!(a > b)` and vice versa; and
215 /// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
216 ///
217 /// Note that these requirements mean that the trait itself must be implemented symmetrically and
218 /// transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T:
219 /// PartialOrd<V>`.
220 ///
221 /// PartialOrd only requires implementation of the `partial_cmp` method, with the others generated
222 /// from default implementations.
223 ///
224 /// However it remains possible to implement the others separately for types which do not have a
225 /// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
226 /// false` (cf. IEEE 754-2008 section 5.11).
227 #[lang = "ord"]
228 #[stable(feature = "rust1", since = "1.0.0")]
229 pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
230     /// This method returns an ordering between `self` and `other` values if one exists.
231     ///
232     /// # Examples
233     ///
234     /// ```
235     /// use std::cmp::Ordering;
236     ///
237     /// let result = 1.0.partial_cmp(&2.0);
238     /// assert_eq!(result, Some(Ordering::Less));
239     ///
240     /// let result = 1.0.partial_cmp(&1.0);
241     /// assert_eq!(result, Some(Ordering::Equal));
242     ///
243     /// let result = 2.0.partial_cmp(&1.0);
244     /// assert_eq!(result, Some(Ordering::Greater));
245     /// ```
246     ///
247     /// When comparison is impossible:
248     ///
249     /// ```
250     /// let result = std::f64::NAN.partial_cmp(&1.0);
251     /// assert_eq!(result, None);
252     /// ```
253     #[stable(feature = "rust1", since = "1.0.0")]
254     fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
255
256     /// This method tests less than (for `self` and `other`) and is used by the `<` operator.
257     ///
258     /// # Examples
259     ///
260     /// ```
261     /// use std::cmp::Ordering;
262     ///
263     /// let result = 1.0 < 2.0;
264     /// assert_eq!(result, true);
265     ///
266     /// let result = 2.0 < 1.0;
267     /// assert_eq!(result, false);
268     /// ```
269     #[inline]
270     #[stable(feature = "rust1", since = "1.0.0")]
271     fn lt(&self, other: &Rhs) -> bool {
272         match self.partial_cmp(other) {
273             Some(Less) => true,
274             _ => false,
275         }
276     }
277
278     /// This method tests less than or equal to (for `self` and `other`) and is used by the `<=`
279     /// operator.
280     ///
281     /// # Examples
282     ///
283     /// ```
284     /// let result = 1.0 <= 2.0;
285     /// assert_eq!(result, true);
286     ///
287     /// let result = 2.0 <= 2.0;
288     /// assert_eq!(result, true);
289     /// ```
290     #[inline]
291     #[stable(feature = "rust1", since = "1.0.0")]
292     fn le(&self, other: &Rhs) -> bool {
293         match self.partial_cmp(other) {
294             Some(Less) | Some(Equal) => true,
295             _ => false,
296         }
297     }
298
299     /// This method tests greater than (for `self` and `other`) and is used by the `>` operator.
300     ///
301     /// # Examples
302     ///
303     /// ```
304     /// let result = 1.0 > 2.0;
305     /// assert_eq!(result, false);
306     ///
307     /// let result = 2.0 > 2.0;
308     /// assert_eq!(result, false);
309     /// ```
310     #[inline]
311     #[stable(feature = "rust1", since = "1.0.0")]
312     fn gt(&self, other: &Rhs) -> bool {
313         match self.partial_cmp(other) {
314             Some(Greater) => true,
315             _ => false,
316         }
317     }
318
319     /// This method tests greater than or equal to (for `self` and `other`) and is used by the `>=`
320     /// operator.
321     ///
322     /// # Examples
323     ///
324     /// ```
325     /// let result = 2.0 >= 1.0;
326     /// assert_eq!(result, true);
327     ///
328     /// let result = 2.0 >= 2.0;
329     /// assert_eq!(result, true);
330     /// ```
331     #[inline]
332     #[stable(feature = "rust1", since = "1.0.0")]
333     fn ge(&self, other: &Rhs) -> bool {
334         match self.partial_cmp(other) {
335             Some(Greater) | Some(Equal) => true,
336             _ => false,
337         }
338     }
339 }
340
341 /// Compare and return the minimum of two values.
342 ///
343 /// Returns the first argument if the comparison determines them to be equal.
344 ///
345 /// # Examples
346 ///
347 /// ```
348 /// use std::cmp;
349 ///
350 /// assert_eq!(1, cmp::min(1, 2));
351 /// assert_eq!(2, cmp::min(2, 2));
352 /// ```
353 #[inline]
354 #[stable(feature = "rust1", since = "1.0.0")]
355 pub fn min<T: Ord>(v1: T, v2: T) -> T {
356     if v1 <= v2 { v1 } else { v2 }
357 }
358
359 /// Compare and return the maximum of two values.
360 ///
361 /// Returns the second argument if the comparison determines them to be equal.
362 ///
363 /// # Examples
364 ///
365 /// ```
366 /// use std::cmp;
367 ///
368 /// assert_eq!(2, cmp::max(1, 2));
369 /// assert_eq!(2, cmp::max(2, 2));
370 /// ```
371 #[inline]
372 #[stable(feature = "rust1", since = "1.0.0")]
373 pub fn max<T: Ord>(v1: T, v2: T) -> T {
374     if v2 >= v1 { v2 } else { v1 }
375 }
376
377 /// Compare and return the minimum of two values if there is one.
378 ///
379 /// Returns the first argument if the comparison determines them to be equal.
380 ///
381 /// # Examples
382 ///
383 /// ```
384 /// # #![feature(core)]
385 /// use std::cmp;
386 ///
387 /// assert_eq!(Some(1), cmp::partial_min(1, 2));
388 /// assert_eq!(Some(2), cmp::partial_min(2, 2));
389 /// ```
390 ///
391 /// When comparison is impossible:
392 ///
393 /// ```
394 /// # #![feature(core)]
395 /// use std::cmp;
396 ///
397 /// let result = cmp::partial_min(std::f64::NAN, 1.0);
398 /// assert_eq!(result, None);
399 /// ```
400 #[inline]
401 #[unstable(feature = "cmp_partial")]
402 pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
403     match v1.partial_cmp(&v2) {
404         Some(Less) | Some(Equal) => Some(v1),
405         Some(Greater) => Some(v2),
406         None => None
407     }
408 }
409
410 /// Compare and return the maximum of two values if there is one.
411 ///
412 /// Returns the second argument if the comparison determines them to be equal.
413 ///
414 /// # Examples
415 ///
416 /// ```
417 /// # #![feature(core)]
418 /// use std::cmp;
419 ///
420 /// assert_eq!(Some(2), cmp::partial_max(1, 2));
421 /// assert_eq!(Some(2), cmp::partial_max(2, 2));
422 /// ```
423 ///
424 /// When comparison is impossible:
425 ///
426 /// ```
427 /// # #![feature(core)]
428 /// use std::cmp;
429 ///
430 /// let result = cmp::partial_max(std::f64::NAN, 1.0);
431 /// assert_eq!(result, None);
432 /// ```
433 #[inline]
434 #[unstable(feature = "cmp_partial")]
435 pub fn partial_max<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
436     match v1.partial_cmp(&v2) {
437         Some(Equal) | Some(Less) => Some(v2),
438         Some(Greater) => Some(v1),
439         None => None
440     }
441 }
442
443 // Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
444 mod impls {
445     use cmp::{PartialOrd, Ord, PartialEq, Eq, Ordering};
446     use cmp::Ordering::{Less, Greater, Equal};
447     use marker::Sized;
448     use option::Option;
449     use option::Option::{Some, None};
450
451     macro_rules! partial_eq_impl {
452         ($($t:ty)*) => ($(
453             #[stable(feature = "rust1", since = "1.0.0")]
454             impl PartialEq for $t {
455                 #[inline]
456                 fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
457                 #[inline]
458                 fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
459             }
460         )*)
461     }
462
463     #[stable(feature = "rust1", since = "1.0.0")]
464     impl PartialEq for () {
465         #[inline]
466         fn eq(&self, _other: &()) -> bool { true }
467         #[inline]
468         fn ne(&self, _other: &()) -> bool { false }
469     }
470
471     partial_eq_impl! {
472         bool char usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64
473     }
474
475     macro_rules! eq_impl {
476         ($($t:ty)*) => ($(
477             #[stable(feature = "rust1", since = "1.0.0")]
478             impl Eq for $t {}
479         )*)
480     }
481
482     eq_impl! { () bool char usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
483
484     macro_rules! partial_ord_impl {
485         ($($t:ty)*) => ($(
486             #[stable(feature = "rust1", since = "1.0.0")]
487             impl PartialOrd for $t {
488                 #[inline]
489                 fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
490                     match (self <= other, self >= other) {
491                         (false, false) => None,
492                         (false, true) => Some(Greater),
493                         (true, false) => Some(Less),
494                         (true, true) => Some(Equal),
495                     }
496                 }
497                 #[inline]
498                 fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
499                 #[inline]
500                 fn le(&self, other: &$t) -> bool { (*self) <= (*other) }
501                 #[inline]
502                 fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
503                 #[inline]
504                 fn gt(&self, other: &$t) -> bool { (*self) > (*other) }
505             }
506         )*)
507     }
508
509     #[stable(feature = "rust1", since = "1.0.0")]
510     impl PartialOrd for () {
511         #[inline]
512         fn partial_cmp(&self, _: &()) -> Option<Ordering> {
513             Some(Equal)
514         }
515     }
516
517     #[stable(feature = "rust1", since = "1.0.0")]
518     impl PartialOrd for bool {
519         #[inline]
520         fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
521             (*self as u8).partial_cmp(&(*other as u8))
522         }
523     }
524
525     partial_ord_impl! { char usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
526
527     macro_rules! ord_impl {
528         ($($t:ty)*) => ($(
529             #[stable(feature = "rust1", since = "1.0.0")]
530             impl Ord for $t {
531                 #[inline]
532                 fn cmp(&self, other: &$t) -> Ordering {
533                     if *self < *other { Less }
534                     else if *self > *other { Greater }
535                     else { Equal }
536                 }
537             }
538         )*)
539     }
540
541     #[stable(feature = "rust1", since = "1.0.0")]
542     impl Ord for () {
543         #[inline]
544         fn cmp(&self, _other: &()) -> Ordering { Equal }
545     }
546
547     #[stable(feature = "rust1", since = "1.0.0")]
548     impl Ord for bool {
549         #[inline]
550         fn cmp(&self, other: &bool) -> Ordering {
551             (*self as u8).cmp(&(*other as u8))
552         }
553     }
554
555     ord_impl! { char usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
556
557     // & pointers
558
559     #[stable(feature = "rust1", since = "1.0.0")]
560     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a A where A: PartialEq<B> {
561         #[inline]
562         fn eq(&self, other: & &'b B) -> bool { PartialEq::eq(*self, *other) }
563         #[inline]
564         fn ne(&self, other: & &'b B) -> bool { PartialEq::ne(*self, *other) }
565     }
566     #[stable(feature = "rust1", since = "1.0.0")]
567     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b B> for &'a A where A: PartialOrd<B> {
568         #[inline]
569         fn partial_cmp(&self, other: &&'b B) -> Option<Ordering> {
570             PartialOrd::partial_cmp(*self, *other)
571         }
572         #[inline]
573         fn lt(&self, other: & &'b B) -> bool { PartialOrd::lt(*self, *other) }
574         #[inline]
575         fn le(&self, other: & &'b B) -> bool { PartialOrd::le(*self, *other) }
576         #[inline]
577         fn ge(&self, other: & &'b B) -> bool { PartialOrd::ge(*self, *other) }
578         #[inline]
579         fn gt(&self, other: & &'b B) -> bool { PartialOrd::gt(*self, *other) }
580     }
581     #[stable(feature = "rust1", since = "1.0.0")]
582     impl<'a, A: ?Sized> Ord for &'a A where A: Ord {
583         #[inline]
584         fn cmp(&self, other: & &'a A) -> Ordering { Ord::cmp(*self, *other) }
585     }
586     #[stable(feature = "rust1", since = "1.0.0")]
587     impl<'a, A: ?Sized> Eq for &'a A where A: Eq {}
588
589     // &mut pointers
590
591     #[stable(feature = "rust1", since = "1.0.0")]
592     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a mut A where A: PartialEq<B> {
593         #[inline]
594         fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
595         #[inline]
596         fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
597     }
598     #[stable(feature = "rust1", since = "1.0.0")]
599     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialOrd<&'b mut B> for &'a mut A where A: PartialOrd<B> {
600         #[inline]
601         fn partial_cmp(&self, other: &&'b mut B) -> Option<Ordering> {
602             PartialOrd::partial_cmp(*self, *other)
603         }
604         #[inline]
605         fn lt(&self, other: &&'b mut B) -> bool { PartialOrd::lt(*self, *other) }
606         #[inline]
607         fn le(&self, other: &&'b mut B) -> bool { PartialOrd::le(*self, *other) }
608         #[inline]
609         fn ge(&self, other: &&'b mut B) -> bool { PartialOrd::ge(*self, *other) }
610         #[inline]
611         fn gt(&self, other: &&'b mut B) -> bool { PartialOrd::gt(*self, *other) }
612     }
613     #[stable(feature = "rust1", since = "1.0.0")]
614     impl<'a, A: ?Sized> Ord for &'a mut A where A: Ord {
615         #[inline]
616         fn cmp(&self, other: &&'a mut A) -> Ordering { Ord::cmp(*self, *other) }
617     }
618     #[stable(feature = "rust1", since = "1.0.0")]
619     impl<'a, A: ?Sized> Eq for &'a mut A where A: Eq {}
620
621     #[stable(feature = "rust1", since = "1.0.0")]
622     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b mut B> for &'a A where A: PartialEq<B> {
623         #[inline]
624         fn eq(&self, other: &&'b mut B) -> bool { PartialEq::eq(*self, *other) }
625         #[inline]
626         fn ne(&self, other: &&'b mut B) -> bool { PartialEq::ne(*self, *other) }
627     }
628
629     #[stable(feature = "rust1", since = "1.0.0")]
630     impl<'a, 'b, A: ?Sized, B: ?Sized> PartialEq<&'b B> for &'a mut A where A: PartialEq<B> {
631         #[inline]
632         fn eq(&self, other: &&'b B) -> bool { PartialEq::eq(*self, *other) }
633         #[inline]
634         fn ne(&self, other: &&'b B) -> bool { PartialEq::ne(*self, *other) }
635     }
636 }